0

I am new in Python and I have this sample code to test some libraries (I've installed all needed libraries with pip).

import matplotlib.pyplot as plt
import numpy

myarray = numpy.array([1, 2, 3])
plt.plot(myarray)
plt.xlabel('some x axis')
plt.ylabel('some y axis')
plt.show()

when I run the code from command line (macOS) via command python main.py I get chart as expected. Bud when I run the same code in Pycharm I get an error related to missing libraries.

/Users/jirka/PycharmProjects/sandbox/venv/bin/python /Users/jirka/PycharmProjects/sandbox/main.py Traceback (most recent call last): File "/Users/jirka/PycharmProjects/sandbox/main.py", line 2, in import matplotlib.pyplot as plt ModuleNotFoundError: No module named 'matplotlib'

Process finished with exit code 1

Q: What I have to set in Pycharm to find installed system libraries?

Edit: I just add to the accepted answer that the Python interpreter can be in Pycharm set globally for all projects.

enter image description here

jnemecz
  • 3,171
  • 8
  • 41
  • 77
  • There's `/venv/bin/python` in your path which means that you're using virtual environment for your project. Virtual environment is an independent *(almost)* copy of python, so you need to install your requirements for this virtual environment. You can check [Install, uninstall, and upgrade packages](https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html) – Olvin Roght Nov 09 '21 at 08:19
  • If you don't want to use virtual environment, you can choose another interpreter. – Olvin Roght Nov 09 '21 at 08:21
  • OK, I will check Pycharm preferences again. – jnemecz Nov 09 '21 at 08:22
  • @bad_coder Not exactly, thanks, but Alexis's answer does. – jnemecz Nov 09 '21 at 08:33
  • @Artegon FYI the linked duplicate target includes the answer by Alexis. – bad_coder Nov 09 '21 at 08:34

1 Answers1

2

Try file -> Settings -> Project : xxxx -> Python Interpreter Then change Python interpreter from venv to your local python.exe

Alexis Leloup
  • 250
  • 1
  • 8