Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Associating a python project with a virtual environment

been searching for this with no success, i don't know if i am missing something but i have a virtualenv already but how do i create a project to associate the virtualenv with, thanks

P.S. Am on windows

like image 749
lulliezy Avatar asked Mar 08 '23 19:03

lulliezy


2 Answers

I could be wrong here, but I do not believe that a virtualenv is something that is by its very nature something that you associate with a project. When you use a virtualenv, you're basically saying, "I'm taking this Python interpreter, installing what I want on it, and setting it aside from the Python interpreter that the entire computer uses by default." Virtualenv does not have a concept of a Python "project"; it is just a custom version of a Python interpreter that you run code through. There are tools in IDEs like PyCharm that enable you to associate a project with a virtualenv, but those are another layer on top of the base software.

In order to use a virtualenv with a project, you will need to "activate" it every time you wish to use it. The documentation for activating a virtualenv on Windows is found here.

EDIT:

Saw that you had virtualenvwrapper tagged in your post, so I did a bit of hunting on that. It would appear that there is the mkproject command, which creates a project folder and then associates it with a virtualenv interpreter. Documentation on it can be found here.

like image 54
nerdenator Avatar answered Mar 20 '23 12:03

nerdenator


Requirements:

  • Virtual Env
  • Pycharm

Go to Virtual env and type which python

Add remote project interpreter (File > Default Settings > Project Interpreter (cog) add remote)

You'll need to set up your file system so that PyCharm can also open the project.

NOTE:

  • do not turn off your virtual environment without saving your run configurations that will cause pycharm to see your run configurations as corrupt
  • There's a button on the top right that reads share enable this and your run configs will be saved to a .idea file and you'll have a lot less issues
like image 20
Tomos Williams Avatar answered Mar 20 '23 11:03

Tomos Williams