Why does venv Python interpreter say "no module named __" when pip freeze & reinstalling indicates the module is installed?

I'm using venv for Python programming for the first time; so I'm assuming my difficulties are coming from that.

I've followed these instructions to create my virtual environment; which seemed to work flawlessly.

Next I followed along with this article but quickly ran into trouble. The command "pip install __" works; but curiously PowerShell seems to hang up after listing "Successfully installed...", pressing enter and spamming keystrokes does nothing; I have to close the PowerShell window. Waiting doesn't seem to do anything either.

After that happened; I figured I broke something so I tried to reinstall the module; in this case matplotlib first, and nmap second, just because nmap was the one I wanted to actually use.

Both returned, after hanging up on the "successful" install, some variation of "Requirement already satisfied: [details about install path here]"

My matplotlib output, for example:

Requirement already satisfied: matplotlib in c:\users\admin\environments\python1\lib\site-packages (3.1.1)
Requirement already satisfied: kiwisolver>=1.0.1 in c:\users\admin\environments\python1\lib\site-packages (from matplotlib) (1.1.0)
Requirement already satisfied: numpy>=1.11 in c:\users\admin\environments\python1\lib\site-packages (from matplotlib) (1.17.2)
Requirement already satisfied: cycler>=0.10 in c:\users\admin\environments\python1\lib\site-packages (from matplotlib) (0.10.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in c:\users\admin\environments\python1\lib\site-packages (from matplotlib) (2.4.2)
Requirement already satisfied: python-dateutil>=2.1 in c:\users\admin\environments\python1\lib\site-packages (from matplotlib) (2.8.0)
Requirement already satisfied: setuptools in c:\users\admin\environments\python1\lib\site-packages (from kiwisolver>=1.0.1->matplotlib) (40.8.0)
Requirement already satisfied: six in c:\users\admin\environments\python1\lib\site-packages (from cycler>=0.10->matplotlib) (1.12.0)

Which also hung up, curiously. It does seem to indicate the package was successfully installed though.

"pip freeze" ALSO supports the idea that these modules ARE installed right; and in my venv no less:

(python1) PS C:\Users\Admin\Environments> pip freeze
cycler==0.10.0
kiwisolver==1.1.0
matplotlib==3.1.1
nmap==0.0.1
numpy==1.17.2
pyparsing==2.4.2
python-dateutil==2.8.0
six==1.12.0

So again, I've never used a venv to program before - I only need to now to use an nmap module and play with some simple networking scripting; but from what I understand using virtual environments to code is the industry standard way of doing things; and thus I want to get the process right.

I'm running Python 3.7.4; and Python HAS been successfully added to PATH, confirmed by typing 'python' in command prompt - though from what I understand it shouldn't matter as each venv for a project is isolated and standalone.

Terribly appreciative of any kind of illumination anyone can provide.

1 Answer

Note that the following answer is relatively generic. Please feel free to follow up with specific questions, clarifications, etc.

Why does my venv Python interpreter say "no module named __" when pip freeze & reinstalling indicates the module is installed?

Just like Python interpreters, there can be multiple versions of pip installed on a system (each one associated with a different interpreter). What this error typically indicates is that you have used a version of pip to install a module that isn't associated with the current version of the interpreter you are using.


Another explanation is that Python has been installed into C:\Programs Files, C:\Program Files(x86) or into another special Windows folder and that is causing issues with finding modules.


I would also add that Powershell may not be the best way to use Python, broadly speaking. It seems to potentially introduce issues that may not exist otherwise.

"pip freeze" ALSO supports the idea that these modules ARE installed right; and in my venv no less[.]

Then you should be able to e.g. import nmap while your virtual environment is activated:

(python1) PS C:\Users\Admin\Environments> python
>>> import nmap
>>>

If you do not see the (python1) i.e. just PS C:\Users\Admin\Environments>, then you are not using the python interpreter associated with your virtual environment and will likely get a "No module named __" error.

It's probably also worth mentioning that Python virtual environments are only associated with a single terminal instance (cmd, powershell, etc.) per activation.

I figured I broke something so I tried to reinstall the module; in this case matplotlib first, and nmap second, just because nmap was the one I wanted to actually use.

Two small points here:

  • Current versions of matplotlib seem to have issues on Windows with Python 3.7.4, at least in some cases (particularly, crashing the Python interpreter).

  • nmap does not appear to have matplotlib as a prerequisite (as far as I am aware).

5

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like