ChatGPT解决这个技术问题 Extra ChatGPT

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?


r
ruddra

For PyCharm 2018

As per documentation from Pycharm:

In the Project Interpreter page, click and select Add. 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. If Existing environment is selected: Specify the required interpreter: use the drop-down list, or click Select an interpreter and find one in your file system. Select the check-box Make available to all projects, if needed. Click OK to complete the task.

For Pycharm 2016 and later

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

In the Project Interpreter page, click . In the drop-down list, choose Add local.

https://i.stack.imgur.com/I226A.png

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:

https://i.stack.imgur.com/aFAgO.jpg

https://i.stack.imgur.com/F9hjd.jpg

https://i.stack.imgur.com/gblfE.png

https://i.stack.imgur.com/6nSlE.jpg

https://i.stack.imgur.com/0nhSq.jpg

Now need to run the project.


this page describes how to add an existing pythong virtualenv jetbrains.com/help/pycharm/2017.1/… however, on OSX, it opens a file dialog, and it doesn't allow to navigate to "hidden" dirs, such as the typical ~/.virtualenvs any idea?
Please correct me if I misunderstood: actually they don't show the hidden directory in the file browser, but if you type the directory name, then type / it will take you inside the hidden folder. It worked for me in 2016 versions. Haven't tested in 2017 edition. Directly copy pasting the path of the python file ie /home/user/proj/.env/bin/python in the file browser also works. @DavidPortabella
it works, thx! when the file dialog appears, typing / will prompt for the path. here it also explains that you can use Command-Shift-. to show hidden files, and Command-Shift-G as an alternative to typing /. intellij-support.jetbrains.com/hc/en-us/community/posts/… osxdaily.com/2011/03/01/…
For IntelliJ, when using Existing Environment option, make sure you have to select [...]/venv/bin/python (not simply [...]/venv/)
G
GodMan

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