简体   繁体   English

Python 找不到已安装的模块

[英]Python does not find installed modules

Python3.5 does not locate installed modules when invoked in virtual env. Python3.5 在虚拟环境中调用时不会定位已安装的模块。

  1. Create virtual env: python3.5 -m venv autogit/venv && cd autogit创建虚拟环境: python3.5 -m venv autogit/venv && cd autogit
  2. source venv/bin/activate
  3. which python == ...autogit/venv/bin/python Weird, would expect python3.5 which python == ...autogit/venv/bin/python奇怪,期望 python3.5
  4. Add my python source code to /autogit and pip freeze>requirements.txt将我的 python 源代码添加到/autogitpip freeze>requirements.txt
  5. pip install -r requirements.txt
  6. ls venv/lib/python3.5/site-packages shows request-0-0-0-py3.5.egg-info and some other stuff ls venv/lib/python3.5/site-packages显示request-0-0-0-py3.5.egg-info和其他一些东西
  7. Since dependencies are installed under python3.5 and which python revealed python rather than python3.5 , lets invoke the python3.5binary explicitly.... venv/bin/python3.5 autogit.py Get ImportError: No module named 'request由于依赖项安装在 python3.5 下并且which python显示 python 而不是python3.5 ,让我们显式调用 python3.5binary.... venv/bin/python3.5 autogit.py Get ImportError: No module named 'request

??? ??? Where could python be looking for packages if not in my virtual env?如果不在我的虚拟环境中,python 可以在哪里寻找包?

UPDATE The questions above remain unanswered;更新上述问题仍未得到解答; here are things I noticed since then and the workaround I used:以下是我从那时起注意到的事情以及我使用的解决方法:

  • pip install produced a file request-0-0-0-py3.5.egg-info . pip install产生了一个文件request-0-0-0-py3.5.egg-info It did NOT produce an actual request directory with the source code or binaries for this module.它没有生成包含该模块的源代码或二进制文件的实际request目录。 Also why is it version 0 0 0 that is fishy还有为什么版本 0 0 0 是可疑的

  • After some googling I noticed the module I wanted seemed to be named requests not request which is what was in my source.经过一番谷歌搜索后,我注意到我想要的模块似乎被命名为requests而不是request ,这是我的源代码中的内容。 I changed it requests, pip install , and everything works.我改变了它的请求, pip install ,一切正常。 It was hard to see that there was a mistake because pip install ing request did not fail很难看出有错误,因为pip install ing request没有失败

Have you got other Python versions installed?您是否安装了其他 Python 版本? That might be the problem.这可能是问题所在。

Try using pip3 instead of pip尝试使用pip3而不是pip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM