[Tutor] Matplotlib.pyplot

Dennis Lee Bieber wlfraed at ix.netcom.com
Fri Apr 14 22:58:09 EDT 2023


On Fri, 14 Apr 2023 18:58:49 -0400, Diana Katz <diana.katz at gmail.com>
declaimed the following:

>I am getting an error when i run my code that i don't have numpy but it
>shows i already installed it. Any advise?
>
>C:\Users\merma\PycharmProjects\pythonProject1\venv\Scripts\python.exe

	This states that you have python installed under the Scripts directory
of a virtual environment

>C:\Users\merma\PycharmProjects\pythonProject1\main.py Traceback (most
>recent call last):   File

	While this indicates your project file itself is /not/ inside the
virtual environment, and is likely using a system-wide python installation.

>"C:\Users\merma\PycharmProjects\pythonProject1\main.py", line 3, in
><module>     import numpy as np ModuleNotFoundError: No module named
>'numpy' Process finished with exit code 1
>

	You have both PyCharm and a virtual environment mentioned. Did you
install numpy INTO the virtual environment? One reason for the virtual
environment (which I've never used) is that one can install modules into
the \venv that are not visible to the outside. And maybe vice-versa --
system-wide modules may not be visible inside the \venv

>
>import numpy as np
>print("numpy version: " + np.__version__)
>numpy version: 1.23.5
>

	Is that from a PyCharm window, Powershell, or plain Windows command
shell. After starting PyCharm, and that \venv, open the "Python Packages"
window and scroll down to see if numpy shows up. And try this in Powershell
-- without starting the \venv

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\Users\Owner> python -m pip list | Select-String "numpy"

numpy                         1.24.2


PS C:\Users\Owner>

	Now start the \venv

PS C:\Users\Owner> python -m venv mytestvenv
PS C:\Users\Owner> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope
CurrentUser

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust.
Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help
topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the
execution policy?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help
(default is "N"): A
PS C:\Users\Owner> .\mytestvenv\Scripts\Activate.ps1
(mytestvenv) PS C:\Users\Owner> python -m pip list | Select-String "numpy"
(mytestvenv) PS C:\Users\Owner>

... shows that creating a virtual environment and activating it does NOT
give access to the system-wide library of installed modules!



More information about the Tutor mailing list