0

I am having 3 small problems which are inter-related.

1.I recently created my own virtual environment ,I want to export that environment to my friend's system so that he can run my environment's main program in one tap.

2.Also where to put main driver python code file in venv so that it can easily be executed in other system.

3.I used open() to read a text file ,but i am not sure what must be its directory so that it can be worked on other(any) system ,i am currently storing it within my venv

What I tried: 1.It is completed so I exported it to other system and (but i am not sure which folder to select so it can be operated on other Window),I copied my_venv directly and pasted it in other system. 2.I stored it within my_venv/main.py 3.I tried open(r'.vmy_env/text.txt','r').

Avishkaar
  • 1
  • 1

1 Answers1

1

You cannot actually move your virtual environment from one system to your friend's system. What you can do instead is :

  1. Create a src folder inside the virtual environment folder and keep all the code files and necessary files related to the project inside this source folder.

  2. Use pip freeze command in order to obtain all the installation details. Store all these details inside a file like requirements.txt. You can do it either by manually copy-pasting or by using output redirection.

  3. Now that we have the requirements and basic structure down, make a virtual environment in another (your friend's) system. Ask him to place the src folder in the exact same place as you did. Then ask him to install all the dependencies using pip (you can follow this link)

  4. Then he should be good to go with the project execution. Another helpful link can be this which shows how to use the above mentioned steps.

A suggested folder structure can be something like this :

+
|
|---- src
|       |
|       |---- main.py
|       |
|       |---- data
|       |       |
|       |       |---- dataset1.csv
|       |       |---- dataset2.csv
|       |       +
|       |
|       |---- utils
|       |       |
|       |       |---- helper.py
|       |       |
|       |       +
|       |
|       |---- requirements.txt
|       |   
|       +
+

Here the main.py is the driver code and all other directories will contain helper/utility functions and classes.

Some good practices while managing Project's folder structure is :

  1. Keep all the code or data files inside the source folder (here src).
  2. Make use of relative paths instead of absolute paths. You can make use of os module in order to do the same. Since it would eliminate the need of modifying the code every time you run it on a different machine or operating system.
  3. Never copy the venv folder. It's only the src folder we need.
  4. Using version control system is a big plus when it comes to effective project management and collaboration. So try looking into git

If you could share your current folder structure then I could help you out more precisely.

Tanishq Vyas
  • 1,422
  • 1
  • 12
  • 25
  • i want to ask if only with gdrive link I want to share my module within my school ,how can they run my application without doing any of these,by just downloading and one tap run of Main program – Avishkaar Dec 21 '20 at 06:13
  • They will require all the libraries in any case in order to run it. A workaround for that can be sharing your google colab notebook with them. That way they dont have to install any package and can directly open the notebook and run it on the google server itself. If this reply helped you then please accept and upvote. These are the only two ways they can do it. Either setup the project or run it on google collab. There is another way where you may send them the python executable file. But that depends on the type of program you have coded, hence I cannot give a green signal for that directly. – Tanishq Vyas Dec 21 '20 at 06:25