How do I add all the dependencies of a python project in a project?

I am installing project dependencies using pip . Pip install all its dependencies to this location

Location: /home/tara/taraproject/myvenv/lib/python2.7/site-packages

What I want to do:

I want to put all the dependencies into the project, not force users to customize it during operations. Just try to remove the load on the installation for the workgroup.

What have I tried?

I tried this inside my ProjectFolder where my working project exists

/ home / tarot / taraprject / ProjectFolder

I created a directory with dependencies and tried to add all dependency modules to it. He made imports like.

from dependencies.yapsy.PluginManager import PluginManager

      

I also created a directory as modules by adding an init .py file .

Traceback (most recent call last):
  File "main.py", line 16, in <module>
    from dependencies.yapsy.PluginManager import PluginManager
  File "/home/tara/taraproject/myvenv/checkaccess/dependencies/yapsy/__init__.py", line 73, in <module>
    from yapsy.compat import is_py2, str
ImportError: No module named yapsy.compat

      

It looks like the import worked, but the internal code of the modules had an error with such an import.

Why try?

If I can do that, the operations team can just get my project and run it easily without having to download dependencies and make the necessary configuration. Just make the operation easier.

How to fix such problems or how to do it?

+3


source to share


1 answer


Based on the description provided, I believe that virtual environments can provide a solution to your question. From an introduction to virtual environments (see links below):

Python applications often use packages and modules that are not included in the standard library. Sometimes applications will need a specific version of the library because the application may require that a specific bug has been fixed or the application may be written using an outdated version of the library interface.

This means that a single Python installation may not meet the requirements of every application. If application A needs version 1.0 of a particular module, but application B needs version 2.0, then the requirements are in conflict and installing version 1.0 or 2.0 will leave one application unable to complete.

The solution to this problem is to create a virtual environment, a stand-alone directory tree containing the Python installation for a particular version of Python, as well as a number of additional packages.

Different applications can then use different virtual environments. To resolve an earlier example of conflicting requirements, application A can have its own virtual environment with version 1.0 installed, while application B has a different virtual environment with version 2.0. If application B requires a library upgrade to version 3.0, this will not affect the application environment.

More information on virtual environments can be found in (quick web search):

Hope it helps.



edit: after comment. The virtual environment can be relocated using the relocation option. From the user manual ( https://virtualenv.pypa.io/en/latest/userguide/#making-environments-relocatable ):

Usually environments are bound to a specific path. This means that you cannot move the environment or copy it to another computer. You can fix the environment to make it relocatable.

See also: Python3 venv: can the env directory be renamed?

Hope this gives you a solution to your problem.

0


source







All Articles