Meow Meow
Meow Meow

Reputation: 666

Move a python project from machine A to machine B including external libraries

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.

Upvotes: 1

Views: 559

Answers (2)

Eeshaan
Eeshaan

Reputation: 1635

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.

Upvotes: 5

Vignesh
Vignesh

Reputation: 1623

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

Upvotes: 3

Related Questions