未找到在 virtualenv 中使用 PIP 安装的模块 [英] Module installed with PIP in virtualenv not found

查看:39
本文介绍了未找到在 virtualenv 中使用 PIP 安装的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遇到一个非常奇怪的错误.我正在创建一个虚拟环境并使用 pip requirements.txt 文件对其进行初始化,但是当我在激活的环境中运行代码时,虚拟环境解释器声称缺少一些(并且只有一些)模块:

Getting a very strange error. I am making a virtual environment and initializing it with a pip requirements.txt file, but when I go to run code in the activated environment, the virtual environment interpreter claims to be missing some (and only some) of the modules:

(venv) $ pip list
certifi (2017.7.27.1)
chardet (3.0.4)
decorator (4.1.2)
idna (2.5)
ipython (6.1.0)
ipython-genutils (0.2.0)
jedi (0.10.2)
numpy (1.13.1)
olefile (0.44)
pexpect (4.2.1)
pickleshare (0.7.4)
Pillow (4.2.1)
pip (9.0.1)
prompt-toolkit (1.0.15)
protobuf (3.3.0)
ptyprocess (0.5.2)
Pygments (2.2.0)
PyYAML (3.12)
pyzmq (16.0.2)
requests (2.18.3)
scipy (0.19.1)
setuptools (38.5.1)
simplegeneric (0.8.1)
six (1.10.0)
torch (0.2.0.post3)
torchvision (0.2.0)
tornado (4.5.1)
tqdm (4.15.0)
traitlets (4.3.2)
urllib3 (1.22)
visdom (0.1.5)
wcwidth (0.1.7)
wheel (0.30.0)

所以我仔细检查:

(venv) $ pip install tqdm 
Requirement already satisfied: tqdm in ./venv/lib/python3.6/site-packages
(venv) $ python  
Python 3.6.3 |Anaconda custom (64-bit)| (default, Oct 13 2017, 12:02:49) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from tqdm import tqdm
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tqdm'

人们建议强制重新安装,使用不同的解释器源,并且只是重新安装.这些都没有奏效.这是非常神秘的.你们有没有见过这样的事情?在此处

people have suggested forcing a reinstall, using a different interpreter source, and just reinstalling. None of these have worked. this is very mysterious. Have any of you seen anything like this? Saw a similar unresolved problem here

更新:已修复.H/T to @Riverman 帮助我找到问题:问题是前一段时间遗留了一个旧的未使用别名,虽然 pip 仍然有自己的指向 python3.6,但 python 命令本身被别名为我躺在某处的一些旧的 Anaconda3 版本.别名,我忘了,不要仅仅通过重新获取您的 .bashrc 文件而消失,所以我使用有问题的 python 命令运行 unalias 并且它起作用了!

UPDATE: Fixed. H/T to @Riverman for helping my find the issue: the problem was that an old unused alias was left over from a while ago, and while pip still had it own point back to python3.6, the python command itself was aliased to some old Anaconda3 version I had lying around somewhere. Alias, I forgot, do not go away by just re-sourcing your .bashrc file, so I ran unalias with the offending python command and it worked!

不过,如果他们能解释为什么会发生这种情况,我仍然很乐意听取他们的意见.我虽然 venv 将您与外部环境完全隔离了...是不是因为混叠是一种系统级效果,所以它会渗入 venv??

Would still love to hear from people though if they could explain why this can occur, though. I though venv completely insulated you from the outside environment...is it because aliasing is a system level effect so it seeps into the venv??

推荐答案

在 virtualenv 中,请发出以下命令:

While being inside the virtualenv, please issue the following commands:

  • pip 冻结
  • pip -V
  • python -V
  • 哪个蟒蛇
  • 哪个点

在此处分享您的结果以进行分析.我之前也遇到过与 requests 包非常相似的问题,但这发生在我的 Windows 上.

Share your results here to analyze it. I've also experienced pretty similar issues with the requests package before, but that happened on windows to me.

这篇关于未找到在 virtualenv 中使用 PIP 安装的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆