StephanieCoding
StephanieCoding

Reputation: 476

Package installed by Conda, Python cannot find it

I try to install Theano by Anaconda. It works, but when I enter the python -i, import theano shows No module named 'theano'. Do I need to switch another interpreter of Python, how? Also, for the packages installed by conda, if I don't double install them, can I find in Python? How is Python related to Python by Anaconda? Thanks!!!

Upvotes: 30

Views: 80685

Answers (6)

Welemir
Welemir

Reputation: 1

Actually for Spyder: the iterator is reset to the default, and you just need to re-select the in Tool -> Preferences -> python interpreter

Upvotes: 0

Monsignor
Monsignor

Reputation: 2955

In my case that happened because conda screwed up the environment variables. Instead of using env-specific python and pip, it used the globally installed ones.

Solution:

conda deactivate your-env
conda activate your-env

Upvotes: 1

Cloud Cho
Cloud Cho

Reputation: 1774

In my workstation, I was able to solve No module named <module name> error using two different ways.

First method, I solved this temporarily by:

(1) Open a Terminal
(2) $ conda activate <Conda environment name>
(3) $ export PYTHONPATH=/home/<user name>/anaconda3/envs/<Conda environment name>/lib/<Python package version>/site-packages:$PYTHONPATH

It is a temporary solution. Whenever you run your virtual environment, you have to do this.

My runtime environment:
    OS: Unbuntu 18.04
    Conda version: 4.8.2
    Conda-build version: 3.18,11
    Python version 3.7.6.final.0

Second method, I removed the
alias python=/usr/bin/python3.6 line in bashrc file.
Somehow this line blocks using Python tools installed in Anaconda Virtual Environment if the Python version in the Virtual Environment is different.

Upvotes: 0

abycoder
abycoder

Reputation: 21

The problem is that in the code editor you are using, you are running the default interpreter. Based on your code editor, change the python interpreter to the conda interpreter and it will work.

Upvotes: 1

Andre Araujo
Andre Araujo

Reputation: 2400

I had have a similar issue, trying to install folium. If you are using the Anaconda:

When you install using conda install -c conda-forge folium, the package will be placed in:

./anaconda3/envs/[name env]/lib/python3.7/site-packages/folium

When you install using pip (with a anaconda env activated), pip install folium, the package will be placed in:

./anaconda3/lib/python3.7/site-packages/folium

Python use first the sites-packages as the target directory of manually built python packages. When you build and install python packages from source (using distutils, probably by executing python setup.py install ), you will find the installed modules in site-packages by default.

In this case you have two places: /anaconda3/lib/python3.7/site-packages/ and /anaconda3/envs/[name env]/lib/python3.7/site-packages/.

First the modules will be available as default in /anaconda3/lib/python3.7/site-packages/. Sometimes (and I really don't know why) the modules inside sites-packages conda env are not available to import automatically without export the PATH.

So, to solve this issue, you have 2 options:

  • Installing using pip install folium and import folium (don't need install by conda install), or

  • After conda install , run conda init, close the terminal and open a new one. So, try to import again.

Here are some tips about use a pip in a conda-environment.

Upvotes: 18

Bishwas Mishra
Bishwas Mishra

Reputation: 1342

You can refer to a specific version of python by using the following at the first line of your .py file This is for python 2.7

#!/usr/bin/env python2.7

This is for python 3

#!/usr/bin/env python3

As other users already pointed out you need to check if your module is included in your sys path. Use code:

import sys
print(sys.path)

If not you can include this in your sys.path by using the command:

sys.path.append('/path/to/the/folder/of/your/module/file')

or place it in default PYTHONPATH itself.

Other great answers: https://stackoverflow.com/a/19305076/5381704

Upvotes: 3

Related Questions