Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using IntellijIdea within an existing virtualenv

I want to use Intellij Idea within my existing python django project which was built within a virtual environment in ubuntu. How do I configure Intellij Idea to use the libraries of the virtual environment?

like image 263
ruddra Avatar asked Jan 02 '14 05:01

ruddra


People also ask

Can I install different Python version in virtualenv?

It's still possible to use a different python version with venv . Instead of providing an argument, like with virtualenv , you just be sure to use the appropriate python version to run venv .

How do I use existing VENV?

You can exit from the virtualenv using exit command, or by pressing Ctrl+d.

How do I add a path to virtualenv?

Just put a file with a . pth extension (any basename works) in your virtualenv's site-packages folder, e.g. lib\python2. 7\site-packages , with the absolute path to the directory containing your package as its only contents.


2 Answers

For PyCharm 2018

As per documentation from Pycharm:

  1. In the Project Interpreter page, click ] and select Add.
  2. In the left-hand pane of the Add Python Interpreter dialog box, select Virtualenv Environment. The following actions depend on whether the virtual environment existed before.

  3. If Existing environment is selected:

    1. Specify the required interpreter: use the drop-down list, or click Select an interpreter and find one in your file system.
    2. Select the check-box Make available to all projects, if needed.
  4. Click OK to complete the task.


For Pycharm 2016 and later

To add an existing virtual environment to the list of available interpreters

  1. In the Project Interpreter page, click enter image description here.
  2. In the drop-down list, choose Add local.

add environment option

  1. In the Select Python Interpreter dialog box that opens, choose the desired Python executable, located inside the virtual environment folder, and click OK.

Go to this link for more information.


For Older versions:

Well I solved the above problem. I have added virtualenv folder's python to project sdk. The virtualenv directory's python( for example venv/bin/python2.7) needs to be added to Intellij Idea project path. Example: need to go to file>project structure (intellij Idea) enter image description here

press new in Project SDK, and add new path to virtualenv's python directory like this:enter image description here

Go to Modules>Dependencies and set your module sdk to Python SDK which is marked on this picture: enter image description here

Click on Django (option marked in next the image) and set Django project root, Settings,Manage Script like this:enter image description here

Now press ok and final look of the Project settings: enter image description here

Now need to run the project.

like image 188
ruddra Avatar answered Oct 03 '22 09:10

ruddra


The above answer is based on older version of IntelliJ. For new, look here: https://www.jetbrains.com/help/pycharm/2016.1/adding-existing-virtual-environment.html

like image 44
GodMan Avatar answered Oct 03 '22 10:10

GodMan