简体   繁体   中英

When inside my VENV, PIP FREEZE shows I have a package installed but when I run my code, it says module not found

I am really at my wit's end right now. 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 environemnt 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'>

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.

在此处输入图像描述

I had same issue when I was installing Opencv when I restarted my pc it worked fine for me. May be help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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