当我的VENV内部时,PIP冻结显示我安装了一个包裹,但是当我运行代码时,它说找不到模块
在创建VENV,激活它并安装一些软件包(Numpy)之后,当我运行具有“导入numpy为NP”的代码时,它会引发一个错误,说找不到模块。我仍在环境中时在CMD中进行了PIP冻结,它向我展示了已安装的Numpy版本。
我很困惑为什么是这种情况,我多次删除并重新创建了环境,但无济于事。
执行PIP列表
和pip冻结
显示此
Package Version
---------- -------
numpy 1.23.0
运行我的程序,该程序导入numpy为NP
会导致此错误
Traceback (most recent call last):
File "c:\Users\User\Desktop\TouristRoutingProblem\TouristRoutingProblem\00 classes\TouristRoutingProblem.py", line 2, in <module>
import numpy as np
ModuleNotFoundError: No module named 'numpy'
当我在CMD中运行以下内容时,
(my_env) PS C:\Users\User\Desktop\TouristRoutingProblem\touristroutingproblem\my_env> python
Python 3.10.5 (tags/v3.10.5:f377153, Jun 6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> print(np)
。输出如下,这表明已安装了Numpy。
<module 'numpy' from 'C:\\Users\\User\\Desktop\\TouristRoutingProblem\\touristroutingproblem\\my_env\\lib\\site-packages\\numpy\\__init__.py'>
After creating a venv, activating it and installing a few packages (Numpy), when I run my code which has "import numpy as np", it throws an error saying module not found. I did a PIP FREEZE in the cmd while still in the environment and it shows me the version of Numpy that is installed.
I am very confused why this is the case, I have deleted and recreated the environment multiple times to no avail.
Doing pip list
and pip freeze
shows this
Package Version
---------- -------
numpy 1.23.0
Running my program which has the line import numpy as np
results in this error
Traceback (most recent call last):
File "c:\Users\User\Desktop\TouristRoutingProblem\TouristRoutingProblem\00 classes\TouristRoutingProblem.py", line 2, in <module>
import numpy as np
ModuleNotFoundError: No module named 'numpy'
Curiously, when I run the following in the CMD this happens.
(my_env) PS C:\Users\User\Desktop\TouristRoutingProblem\touristroutingproblem\my_env> python
Python 3.10.5 (tags/v3.10.5:f377153, Jun 6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> print(np)
The output is as follows, which suggests that numpy IS installed.
<module 'numpy' from 'C:\\Users\\User\\Desktop\\TouristRoutingProblem\\touristroutingproblem\\my_env\\lib\\site-packages\\numpy\\__init__.py'>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 ctrl + shift + p 命令打开命令调色板,搜索并选择 python:选择解释器 (或直接单击右下角显示的 python版本),然后选择正确的解释器。
Use the Ctrl+Shift+P command to open the Command Palette, search for and select Python:Select Interpreter(Or click directly on the python version displayed in the lower right corner), and select the correct interpreter.