简体   繁体   English

python找不到安装在windows上的模块

[英]python cannot find module that is installed on windows

I have installed the requests module我已经安装了请求模块

C:\Python34\Scripts\easy_install.exe requests

i got to the folder location我到了文件夹位置

C:\Python34\Lib\site-packages\requests-2.13.0-py3.4.egg\requests

I have a path variable in system我在系统中有一个路径变量

C:\Python34\Lib\site-packages

yet when i run my script然而当我运行我的脚本时

C:\Users\beast\Desktop>update.py

I get the error No module named 'requests'我收到错误 No module named 'requests'

Traceback (most recent call last):
  File "C:\Users\beast\Desktop\plex_playlist_update.py", line 17, in <module>
    import requests
ModuleNotFoundError: No module named 'requests'

I tried installing using pip just in case我尝试使用 pip 安装以防万一

python -m pip install requests
Requirement already satisfied: requests in c:\python34\lib\site-packages\requests-2.13.0-py3.4.egg

I am new to python and I cant find an answer anywhere.我是 python 新手,在任何地方都找不到答案。

UPDATE:更新:

I found a command to check my python search location.我找到了一个命令来检查我的 python 搜索位置。

C:\Users\beast\Desktop>python -c "import site; print(site.getsitepackages())"
['C:\\Python34', 'C:\\Python34\\lib\\site-packages']

I think it has to do with C:\\Python34 vs C:\\python34?我认为它与 C:\\Python34 vs C:\\python34 有关? How do i check or fix this?我如何检查或解决这个问题?

The problem here is maybe because of the different versions of python installed.这里的问题可能是因为安装了不同版本的python。 If you are a Windows user, you can go to Path in Environment variables and remove the paths to unnecessary versions of python (if any).如果您是 Windows 用户,则可以转到环境变量中的 Path 并删除不必要的 Python 版本(如果有)的路径。 Modules installed for one version of python won't work in another version.为一个版本的 python 安装的模块在另一个版本中不起作用。

So I ended up going with python environment.所以我最终选择了 python 环境。 Per python documentation it is the way to go anyway.根据 python 文档,无论如何都是要走的路。 The below command are run on the root folder of the python app.以下命令在 python 应用程序的根文件夹上运行。

py -m venv env then ./env/Scripts/activate py -m venv env然后./env/Scripts/activate

I then ran my pip upgrade and everything is working.然后我运行了我的 pip upgrade 并且一切正常。 Obviously this did not fix it computer wide.显然,这并没有在计算机范围内修复它。 just for my python app.仅适用于我的 python 应用程序。 But from documentation this is better because of version control of the whole enviroment.但是从文档来看,这更好,因为整个环境的版本控制。

This creates a "env" folder at the root which will have all the packages installed.这将在根目录创建一个“env”文件夹,其中将安装所有软件包。 Need to install all requirements again or use the requirements.txt file.需要重新安装所有需求或使用 requirements.txt 文件。

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

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