0

is there any method to create standalone .pyc program that will contain all modules inside, I just don't want to install all modules on every computer where I want to run this program. If this is not possible what else can I do?

1
  • .pyc files are not compiled versions, it's just optimized bytecode to speed up module loading. So, it won't work as you expect. In order to have "all modules inside" you might want to convert python script to executable file using something like py2exe Commented Jun 4, 2014 at 11:29

2 Answers 2

1

You could install python packages locally inside your project, using command:

pip install -t <destination_folder> <package_name>

For example:

pip install -t . mock

Will install mock library into current directory. Then, when you do import mock in the files from that folder, you will be given local file.

You could also install all packages into subfolder of your project called lib or similarly, and than before you import that package call:

import sys; sys.path.insert(0, path_to_lib_folder)
Sign up to request clarification or add additional context in comments.

3 Comments

It should be mentioned that by embedding packages in your project you will need to update them whenever new releases are made. This is probably a Bad Idea for something that might get security fixes, like cryptography or passlib.
@otus Nice remark. But on the other hand - it will could to avoid errors caused by incompatible versions.
Yes, but so will requiring a specific version in setup.py.
1

You need to create virtual python environment.

There are two ways:

  1. VirtualENV. It creates virtual environment. So you can install python modules in it and just copy to another server.

  2. (RECOMMENDED) Buildout. It also creates virtual environment. However you don't need to install all things and update every time you need. You just need to write simple buildout config and buildout install everything for you and keeps it up to date. Also buildout can install software which may be non-Python-based, for example some kind of database and so on. And everything will be installed locally in virtual environment.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.