1

I need to copy my project from machine A to machine B. If I copy the project to another machine I need to install all external libraries/frameworks for python before that. Is it possible to include all imported external libraries and frameworks into the project structure?

For instance, I'm using Flask inside of the project. I would like to configure my project in a way when I do not need to install Flask in machine B to run the project.

If I would like to solve the same task in java I just need to create a war/jar file. After that, just copy a jar file to the machine B.

Machine B does not have access to the internet so I can't use pip freeze / pyinstaller.

Meow Meow
  • 637
  • 6
  • 17
  • 1
    Related: https://stackoverflow.com/questions/37606773/how-to-build-python-project-including-dependencies and https://stackoverflow.com/questions/25559157/how-to-handle-python-dependencies-throughout-the-project – Tomerikoo Oct 22 '20 at 13:22
  • 1
    Does this answer your question? [How to build Python project including dependencies?](https://stackoverflow.com/questions/37606773/how-to-build-python-project-including-dependencies) – Tibebes. M Oct 22 '20 at 13:24
  • @Tomerikoo Machine B does not have access to the Internet. This is why I can't use solutions of the linked topics – Meow Meow Oct 22 '20 at 13:43
  • My solution doesn't require any internet connection. Please consider accepting and upvoting, if you find it useful. – Eeshaan Oct 22 '20 at 15:25

2 Answers2

5

Normally you create a requirements.txt file and list out all the dependencies of your project in it, so that a single installation command can be used to install those dependencies on a different system (or re install on the same system). This is the answer given by @Vignesh Rajendran.

However for this method to work, the new system must have an internet connection. But since you stated that's not the case, you can use the below method instead.

Have a virtual environment. When you need to move the project to a new system, you can move the environment folder along with the source code. You can find a good tutorial for the same here.

Eeshaan
  • 1,557
  • 1
  • 10
  • 22
3

My suggestion is to create a requirement file / Executable file

For Requirement file:(Option 1) you can create a requirements.txt file by using the below command from Machine A.

pip freeze > requirements.txt

the file looks like this

numpy==1.18.4
openpyxl==3.0.3
pandas==1.0.3

and then copy your code along with the requirements.txt file to machine B and enter this command

pip install -r requirements.txt

All the Packages in the Machine A will be installed to B using a single command

For Executable file:(Option 2)

installer Pyinstaller in Machine A and create Executable using below command

pip install pyinstaller
pyinstaller --onefile yourscript.py

exe will be generated and available in the dist Folder copy this to Machine B

But this needs some changes in code for folder paths and hardcoded stuffs as exe cann't be edited on Maachine B

Vignesh
  • 1,553
  • 1
  • 10
  • 25
  • Thank you for your response. Can you clarify, please does machine B need to have access to the internet to install all external libraries or the exe file will contain them? – Meow Meow Oct 22 '20 at 13:36
  • yes, it needs internet access for installing the packages from the requirements.txt file – Vignesh Oct 22 '20 at 13:39
  • 1
    But the Exe option doesn't need an internet connection – Vignesh Oct 22 '20 at 13:39