Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do I put my python files in the venv folder?

(Probably a noob question, but I didn't find a solution after googling for 20 minutes.)

I created a new pure Python project with PyCharm which yielded the following folder structure

myproject └── venv     ├── bin     │   ├── activate     │   ├── activate.csh     │   ├── activate.fish     │   ├── easy_install     │   ├── easy_install-3.5     │   ├── pip     │   ├── pip3     │   ├── pip3.5     │   ├── python     │   ├── python3     │   └── python3.5     ├── include     ├── lib     │   └── python3.5     ├── lib64 -> lib     └── pyvenv.cfg 

Where do I put myproject.py or the myproject folder now?

  • Inside or outside of venv?
  • In the venv/binfolder?
  • Just inside venv, i.e. myproject/venv/myproject.py?
like image 597
problemofficer - n.f. Monica Avatar asked Jul 24 '18 13:07

problemofficer - n.f. Monica


People also ask

Where are Python environments saved?

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.


2 Answers

The virtual environment manages files which aren't yours. It doesn't care how you manage your own files. Put them wherever makes sense to you, just not anywhere inside the venv directory tree. Common solutions include directly in myproject, or in myproject/src.

like image 150
tripleee Avatar answered Sep 23 '22 07:09

tripleee


I guess you misunderstood the term "Virtual Environment". It provides an isolated environment wherein you can download a different version of python packages and run it for your project. Hence, do not put anything inside your virtual environment. Keep it clean.

To take advantage of the virtual environment,

  • activate it (source path_to_virtual_env/bin/activate )
  • install the necessary python packages using pip (pip install XYZ)
  • and run your python code using python command (python3 mycode.py)
like image 32
JR ibkr Avatar answered Sep 26 '22 07:09

JR ibkr