Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installed a package with Anaconda, can't import in Python

Tags:

Forgive me but I'm new to python. I've installed a package (theano) using conda install theano, and when I type conda list, the package exists

However, when I enter the python interpreter by running python, and try to import it with import theano, I get an error: "no module named theano", and when I list all python modules, theano doesn't exist.

What am I missing?

like image 356
KDogg Avatar asked Apr 19 '17 02:04

KDogg


People also ask

How do I import anaconda packages?

Go to Environments tab just below the Home tab and from there we can check what all packages are installed and what is not. It is very easy to install any package through anaconda navigator, simply search the required package, select package and click on apply to install it.

How do I enable Python after installing anaconda?

Click Start�All Programs�Anaconda (64-bit)�Anaconda Command Prompt. � A command prompt window will open. Type idle to run the Python interpreter. A new window titled Python Shell will open and you will see the Python >>> command prompt.

How do you import a package in Python?

Importing module from a package We can import modules from packages using the dot (.) operator. Now, if this module contains a function named select_difficulty() , we must use the full name to reference it. Now we can directly call this function.

How do I know if my anaconda packages are installed?

Start the Anaconda Navigator application. Select Environments in the left column. A dropdown box at the center-top of the GUI should list installed packages. If not, then select Installed in the dropdown menu to list all packages.


2 Answers

Probably due to the fact you have multiply python envs installed in your computer. when you do which python you will probably get the native python installed in your computer. that is /usr/bin/python

You want to use the Python that came when you installed Anaconda. Just add Anaconda path to the beginning of your $PATH. (In order to do this you probably need to edit your ~/.bashrc file (or the equivalent file for your shell) then source ~/.bashrc.

Next time you will go to will run python and import theano you'll succeed.

like image 151
mataney Avatar answered Oct 23 '22 18:10

mataney


When I had this issue my python install was actually missing a "site-packages" path reference. To solve/workaround the issue do the following.

  1. Search for your newly installed package from the Anaconda directory and note the path. (e.g. C:\Anaconda\site-packages)
  2. Run the following in your terminal:
        python -c "import site; print(site.getsitepackages())"

Example Output: ['C:\Anaconda3', 'C:\Anaconda3\lib\site-packages']

  1. If the path noted in step one is missing from the list then that's your problem. The quick fix is to move the new package to a listed site-packages folder or add the missing path to your PYTHONPATH environment variable.

If you're interested in managing your own "site-packages" locations check out the Python Doc for details on setting up a site config file.

like image 23
James Callender Avatar answered Oct 23 '22 19:10

James Callender