ViennaRNA error: ImportError: No module named _RNA
3
0
Entering edit mode
10.5 years ago
tfadgreef • 0

Dear all,

I recently compiled ViennaRNA 2.1.7 using the following options:

./configure --prefix=/usr/local/ViennaRNA --with-python
make
sudo make install

However, when I open Python and I type:

import RNA

I get the following error:

ImportError: No module named _RNA

What is going wrong?

python viennrna • 13k views
ADD COMMENT
0
Entering edit mode

The use of --prefix=/usr/local/ViennaRNA is non-standard. Simply using --prefix=/usr/local (which is also the default) would have done the trick since /usr/local/lib/python... should already be in your PYTHON_PATH

ADD REPLY
3
Entering edit mode
10.5 years ago

I'm guessing that /usr/local/ViennaRNA isn't in your PYTHONPATH. So either change that or just:

import sys
sys.path.append("/usr/local/ViennaRNA")

It's likely that the python stuff is in a subdirectory, so modify as needed.

ADD COMMENT
2
Entering edit mode
6.0 years ago

For future reference, since there is not much help for the ViennaRNA-2.4.10 package:

I ran into this error after installing the package with the python3 interface. I found a fix for me:

Go to the directory: /usr/local/lib/python3.5/site-packages you should find the directory /RNA which should contain the __init__.py file that tells python to consider this directory for importing a library.

You should also find a .so file, rename that file to be _RNA.sosee: http://www.swig.org/Doc1.3/Python.html#Python_nn9

A common error received by first-time users is the following:

>>> import example 
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "example.py", line 2, in ?
import _example
ImportError: No module named _example

If you get this message, it means that you either forgot to compile the wrapper code into an extension module or you didn't give the extension module the right name. Make sure that you compiled the wrappers into a module called _example.so. And don't forget the leading underscore (_).

This solved my import error. Hope this helps

ADD COMMENT
1
Entering edit mode
3.5 years ago
nicolas ▴ 10

7 years later, but I was still struggling with the same problem. Until I realized, that it can be very easily installed with conda: https://anaconda.org/bioconda/viennarna

conda install -c conda-forge -c bioconda viennarna

Hope that saves some time to someone else that I lost with the unnecessarily complicated viennarna installation guidelines.

ADD COMMENT
1
Entering edit mode

I have been trying to import viennarna in python for days. This solution get stucked in:

$ conda install -c conda-forge -c bioconda viennarna Collecting package metadata (current_repodata.json): done Solving environment: failed with initial frozen solve.

Any ideas?

edit: solved installing from https://www.tbi.univie.ac.at/RNA/#download? and running: export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.8/site-packages/

ADD REPLY
0
Entering edit mode

As a rule of thumb you're best off making new environments when possible, as that will prevent failed environment resolution.

ADD REPLY
0
Entering edit mode

It worked for me when I exported PYTHONPATH:

export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.8/site-packages/

Thank you so much!

ADD REPLY

Login before adding your answer.

Traffic: 2469 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6