curious
curious

Reputation: 11

Is there any way to package python code so that other machine does not need to install all the dependencies using pip

I have installed python in my system and wrote a simple script using GET REST API for Jenkins data.

I have installed all the required modules using pip. Now I want to package this script with all the dependencies and run on another machine. However, in another machine, I don't want to perform all the pip installation steps.

I know we can mention all the modules in the requirements.txt and use pip install -r requirements.txt. But, is there any way so that I don't need to install modules using pip for each dependency, such that I can install Python and all other dependencies must be installed when I run the zip file.

Upvotes: 1

Views: 633

Answers (2)

I think you should use virtualenv module which makes your project easily deploy-able. Virtual Environment should be used whenever you work on any Python based project. It is generally good to have one new virtual environment for every Python based project you work on. So the dependencies of every project are isolated from the system and each other.

I came across a link which can help Virtual Env explained

Upvotes: 0

adamkgray
adamkgray

Reputation: 1937

You can install pip dependencies to a certain directory using -t (target).

pip install -r requirements.txt -t .

That will install your pip modules to the current directory. You can zip the whole thing then and deploy. Make sure that the environment you install the dependencies in matches your intended deployment environment. For consistency you can run the command in a docker container, for example.

Upvotes: 1

Related Questions