[英]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.