Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do I store my python program files when using a virtual environment? [closed]

I created a virtual environment called .lpvenv which contains dependencies for my project. On windows, .lpvenv is basically a folder. Do I store my source code directly in this folder when working inside .lpvenv or does it not matter ?

Let's say I have a folder learning.python, inside this folder i have .lpvenv do i put my source code in learning.python or inside .lpvenv ?

like image 475
Mutating Algorithm Avatar asked Feb 05 '23 19:02

Mutating Algorithm


2 Answers

You put your python code inside the learning.python.

Your directory structure would look something like this:

  • learning_python
    • .lpvenv
    • code.py
    • another_code.py
    • some_python_package

If you run source .lpvenv/bin/activate on Linux or OSX or .lpvenv\Scripts\activate.bat on Windows, you will be using your venv interpreter, otherwise, you will be using your system interpreter.

like image 67
vribeiro Avatar answered Feb 08 '23 16:02

vribeiro


The environment folder should never be touched. It's there to store the specific version of python as well as the modules you install into that environment. All of this is managed by PIP.

You can put your code anywhere you want in your project directory as long as you call the .lpenv/bin/activate script to activate your environment first. However, most projects put the environment right next to their source code within their project folder, which would be learning.python in your case.

If you're using version control such as Git, make sure you add .lpenv to your .gitignore file. You do not want to commit your environment into source code since it should be easily rebuilt using your requirements.txt file.

like image 23
Soviut Avatar answered Feb 08 '23 15:02

Soviut