无法导入我刚刚安装的软件包

时间:2018-06-20 14:25:58

标签: python python-3.x virtualenv packages

我创建了一个虚拟环境,安装了熊猫,并尝试将其导入:

$ pip install pandas ...
...
Installing collected packages: numpy, pandas...
$ find $VIRTUAL_ENV -name pandas
/home/sds/.virtualenvs/myenv/lib64/python3.6/dist-packages/pandas
$ python -c 'import pandas'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'pandas'
$ python --version
Python 3.6.5
$ pip --version
pip 10.0.1 from /home/sds/.virtualenvs/myenv/local/lib/python3.6/dist-packages/pip (python 3.6)
$ wh python 
python is /home/sds/.virtualenvs/myenv/bin/python
$ wh pip
pip is /home/sds/.virtualenvs/myenv/bin/pip

我注意到的一个怪异现象是:

$ ls /home/sds/.virtualenvs/myenv/lib*/python3.6/site-packages/
/home/sds/.virtualenvs/myenv/lib/python3.6/site-packages/:
total 0

/home/sds/.virtualenvs/myenv/lib64/python3.6/site-packages/:
total 0

我在做什么错了?

“解决方法”是:

cd $VIRTUAL_ENV/myenv
for d in lib lib64; do
  cd $d/python3.6
  rmdir -v site-packages && mv -v dist-packages site-packages
  cd ../..
done

很明显,出了点问题...

PS。 virtualenv设置:

pip3 install --user virtualenv virtualenvwrapper
pip3 install --user --upgrade virtualenv virtualenvwrapper
mkvirtualenv -p python3 myenv

1 个答案:

答案 0 :(得分:0)

我只能猜测您正在使用哪个系统。我发现在Mac上,我必须对要与python 3.6。*一起使用的软件包使用pip3 install ...