comiventor
comiventor

Reputation: 4142

Configuring PyCharm with existing virtualenv

I am trying to get PyCharm running using existing virtualenv setting. I have pointed my PyCharm project to python interpreter in existing virtualenv ~/.virtualenvs/myproj/ in the following path

File -> Default Settings -> Default Project -> Python Interpreter

the project runs fine but the editor is still glowing RED on packages installed as part of the virtualenv.

Any idea what I am missing?

Upvotes: 20

Views: 43034

Answers (5)

VARAT BOHARA
VARAT BOHARA

Reputation: 455

For Ubuntu users:

Step 1: Go to: "File > Settings > Python Interpreter"
Step 2: Drop down the Python Interpreter options and select "Show All..."
Step 3: Click on the left top "+" symbol to add your virtual environment
Step 4: Under Virtual Environment, select "Existing environment"
Step 5: By clicking the three dots at right side, link to the python 
        interpreter of your virtual environment. 
        For me, the linking looks like this: "/home/varat/cv/bin/python3"
        My virtual environment name is "cv"
Step 6: Finally, click "OK"

After some loading, the pycharm will be working under your linked virtual environment.

Upvotes: 4

hestellezg
hestellezg

Reputation: 3711

For PyCharm 19.3

Ctrl + Alt + S or File / Settings

then

Project: your-name-project / Project Interpreter / Gear Icon / Add ...

Choose New environment

in Location:

set your path / to / venv

Finally, you should see

Project Interpreter : path / to / venv / Scripts / python.exe

Upvotes: 2

Aseem
Aseem

Reputation: 6787

enter image description here Dont click on make available to all projects and it will work. Otherwise it would give error saying -- specify a different sdk name

Upvotes: 12

onofricamila
onofricamila

Reputation: 1089

I did what was specified by comiventor in the accepted answer, but also had to do what Brian W commented: mark the root folder as a "Sources Root". This is done as follows:

  • Right click on your root directory
  • Look at the bottom for the option Mark Directory as
  • Choose Sources Root (the folder icon color should change from gray to blue)

That's all!

Upvotes: 2

comiventor
comiventor

Reputation: 4142

To run PyCharm properly for your project, you need to set Python Interpreter and Python Structure correctly.

I had set Python Interpreter correctly but missed out on Python Structure.

Go to Pycharm->Preferences->your_project->Project Structure

Add the right content root

It has nothing to do with your working directory which you can set separately in your debug/run configuration

also don't forget to add environment variables you need and you should be good to go.

For Intellij Idea 2016.2, following is the path to add site-packages installed in virtualenv File -> Project Structure -> Sources -> "Use + button and add as Sources"

if hidden directory may is be visible, you may either change your view settings or copy paste the path to site-packages in virtualenv

Upvotes: 12

Related Questions