Configuring PyCharm with existing virtualenv
Solution 1
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
Solution 2
Dont click on make available to all projects
and it will work. Otherwise it would give error saying -- specify a different sdk name
Solution 3
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!
comiventor
if thou can't invent the wheel, work on the spokes. I have a joke on UDP, you might not get it. I have a joke on NullPointerException but you can't handle it I have a joke of O(n) but everyone wants logarithmic. I have a joke on DFS, but it's too deep. I have a joke on Dijkstra's Algorithm, but I am finding the shortest way to tell it.
Updated on July 09, 2022Comments
-
comiventor almost 2 years
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?
-
Brian W over 5 yearsa little clarification on "Add the right content to root". What worked for me with an existing Python 2.7.15 virtual environment was this... With <project folder> as root, I marked
<project folder>/src
asSources
(shows up blue in Pycharm 2018). I had previously selected<project folder>/Scripts/python.exe
as my interpreter. -
Nilesh Kesar almost 3 yearsI had to click on the make available to even see the venv appear in the project interpreter