简体   繁体   English

为什么我的模块没有安装在我当前的 python 环境中?

[英]Why don't my modules install in my current python environment?

I have a recurrent problem I have yet been unable to find an answer to.我有一个反复出现的问题,我还没有找到答案。
Whenever I install a package in PyCharm through the terminal, whenever I try importing the module the package appears to not be installed.每当我通过终端在 PyCharm 中安装 package 时,每当我尝试导入模块时,package 似乎都没有安装。 Or, like just now, the package may already be installed but when importing the module I get the error "No module named x" :或者,就像刚才一样,package 可能已经安装,但是在导入模块时出现错误“No module named x”

C:\Users\TimStack\PycharmProjects\API>pip install requests
Requirement already satisfied: requests in c:\users\TimStack\appdata\local\programs\python\python37\lib\site-packages (2.23.0)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\TimStack\appdata\local\programs\python\python37\lib\site-packages (from requests) (2019.11.28)
Requirement already satisfied: idna<3,>=2.5 in c:\users\TimStack\appdata\local\programs\python\python37\lib\site-packages (from requests) (2.9)
Requirement already satisfied: chardet<4,>=3.0.2 in c:\users\TimStack\appdata\local\programs\python\python37\lib\site-packages (from requests) (3.0.4)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\TimStack\appdata\local\programs\python\python37\lib\site-packages (from requests) (1.25.8)

Looking at these directories, it seems to refer to an old Python 3.7 installation.查看这些目录,似乎是指一个旧的 Python 3.7 安装。 However, my environment uses 3.8 .但是,我的环境使用3.8

What's the issue at hand here, and how do I go about solving it?这里有什么问题,我该如何解决它?

You need to uninstall the old 3.7 version as you have 2 conflicting Python versions.您需要卸载旧的 3.7 版本,因为您有 2 个冲突的 Python 版本。

OR或者

Specify your Python version when installing packages:安装包时指定您的 Python 版本:

pip3.8 install [package name]

(3.8 for Python 3.8) (3.8 用于 Python 3.8)

pip install takes --python-version <python_version> as argument. pip install--python-version <python_version>作为参数。 You can pass 3.8 as argument and it will pick up the right one for you.您可以将 3.8 作为参数传递,它会为您选择正确的参数。

from the docs -从文档 -

The Python interpreter version to use for wheel and "Requires- Python" compatibility checks. Python 解释器版本用于轮子和“Requires-Python”兼容性检查。 Defaults to a version derived from the running interpreter.默认为从正在运行的解释器派生的版本。 The version can be specified using up to three dot-separated integers (eg "3" for 3.0.0, "3.7" for 3.7.0, or "3.7.3").可以使用最多三个点分隔的整数指定版本(例如,“3”表示 3.0.0,“3.7”表示 3.7.0,或“3.7.3”)。 A major-minor version can also be given as a string without dots (eg "37" for 3.7.0).主要-次要版本也可以作为不带点的字符串给出(例如,“37”代表 3.7.0)。

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

相关问题 我的python模块(matplotlib,numpy)无法正常工作 - my python modules (matplotlib, numpy) don't work 为什么 Anaconda 在我的基础环境中显示模块? - Why is Anaconda showing modules in my base environment? 为什么要在我当前的virtualenv之外安装python包呢? - Why would pip install python packages outside of my current virtualenv? 如何在我当前的mac(而不是2.6)python2.7安装中创建pip安装python模块? - How to make pip install python modules in my current python2.7 installation on mac (instead of 2.6)? 为什么我的 python package 没有安装在我的 virtualenv 中? - Why my python package doesn't install in my virtualenv? 为什么我的 flask 应用程序在我的环境中没有安装任何模块的情况下运行? - Why is my flask app running with no modules installed in my environment? 更改 Python 模块的权限,这样我就不需要“sudo”我的 Python 脚本调用 - Changing Permissions on Python Modules so I Don't Need to “sudo” My Python Script Calls 为什么python不能读取我的环境变量? - Why can't python read my environment variables? 为什么我写的文件没有把输入的文字保存在Python中? - Why don't my written files not save the inputted text in Python? 学习Python; 不知道为什么我的功能不能正常工作 - Learning Python; don't know why my function works improperly
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM