当我的VENV内部时,PIP冻结显示我安装了一个包裹,但是当我运行代码时,它说找不到模块

发布于 2025-02-14 00:49:45 字数 1178 浏览 1 评论 0原文

在创建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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

万人眼中万个我 2025-02-21 00:49:45

使用 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.

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文