-1

I open a PyCharm project (Windows 11) and inside PyCharm I run the terminal to install some requirements:

pip install -r requirements.txt

However, when opening a Python file from the same project in the same folder all the modules that should be imported are marked in "red", i.e. "unresolved reference".

It seems that the terminal in PyCharm and PyCharm use a different Python interpreter. Running this on Windows I check what Python is used in the terminal and do:

where python

but I do not get any output.

How to set this up correctly, so that when I install something on the terminal inside PyCharm, PyCharm actually uses that?

python -V
Python 3.10.11
3
  • 1
    youtube.com/watch?v=04T7rnhZ2YY make sure a virtualenvironment has been set for the current project. so each time pycharm opens that project it knows there's a assigned virtual environment with that project and it applies it everywhere: run, debug, terminal, etc. Commented Oct 11 at 6:37
  • Thanks a lot, I saved that video, it seems to have solved this issue for now Commented Oct 11 at 6:56
  • as I remeber PyCharm has built-in function to install modules for Python which is assigned to project. You may also run in code print( sys.executable ) to get /full/path/to/python.exe and later use it in terminal /full/path/to/python.exe -m pip install ... Commented Oct 11 at 18:37

1 Answer 1

1

On the bottom right of the PyCharm screen you will be able to setup the interpreter options for your project like creating a new one (with venv, conda, poetry etc) or switch between multiple interpreters (if you need to test you app with multiple versions of python for example).

Easier one to use in my opinion is venv, it will create a .venv folder in the project and store the installed modules there.

More information here in the official docs: https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html#interpreter

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.