0

My environment

$ cat /etc/centos-release
CentOS Linux release 7.3.1611 (Core)

$ python --version
Python 3.6.3 :: Anaconda, Inc.

I created a virtual environment and using it; Set environment variables;

$ sudo chown -R tonynb:tonynb anaconda3     # anaconda3 owns to me

$ which python
/opt/anaconda3/bin/python

$ conda create --name ve        # My virtual environment

$ source activate ve

(ve)$ which python
/opt/anaconda3/envs/ve/bin/python

I started to install packages

(ve)$ pip install pymongo

(ve)$ pip install jupyter notebook

(ve)$ jupyter notebook

(ve)$ pip freeze
pymongo==3.5.1
jupyter==1.0.0
jupyter-client==5.1.0
jupyter-console==5.2.0
jupyter-core==4.4.0
....

Everything is fine. But when I am in jupyter notebook, error happened when I type this

import pymongo
ModuleNotFoundError: No module named 'pymongo'

It seems that it only search packages inside

/opt/anaconda3/lib/python3.6/site-packages not /opt/anaconda3/envs/ve/lib/python3.6/site-packages

$ which pip
/opt/anaconda3/bin/pip 

(ve)$ which pip
/opt/anaconda3/envs/ve/bin/pip

Did I misunderstand something? Or anything goes wrong?

darthbith
  • 18,484
  • 9
  • 60
  • 76
Tony Chou
  • 584
  • 1
  • 9
  • 26
  • 1
    What is the output of `which pip`? You did not install any packages into the environment when you created it, so I'm very surprised that Python is available from that environment. Moreover, you should use conda to install packages whenever possible, since pip and conda don't interact with eachother – darthbith Nov 26 '17 at 14:51
  • @darthbith `/opt/anaconda3/envs/ve/bin/pip`. I edit last part of my code. Do you mean I shouldn't use `pip install ` in my virtual environment? – Tony Chou Nov 26 '17 at 16:36
  • 1
    Yes, you should use `conda install` – darthbith Nov 26 '17 at 16:43
  • Thanks @darthbith. It works. But it seems I can not use `conda install -r requirement` like pip. – Tony Chou Nov 26 '17 at 16:49
  • 1
    That's correct. You have to use an environment file. See https://gist.github.com/luiscape/19d2d73a8c7b59411a2fb73a697f5ed4 and https://groups.google.com/a/continuum.io/forum/#!topic/conda/PiM9sjWyXFU and https://stackoverflow.com/questions/35245401/combining-conda-environment-yml-with-pip-requirements-txt – darthbith Nov 26 '17 at 16:55
  • What is your `conda list --export > requirements.txt` output? – roadRunner Feb 05 '20 at 17:05

0 Answers0