Quickly and carelessly you can "fix", doing so:
In the environment of your project do:
$ pip freeze > requirements.txt
In the production environment, do:
$ pip install -r requirements.txt
Because although quick and easy, this form can be considered "careless"? because that way you will be installing in production all the packages installed in the development environment, this, most of the time, unnecessary.
But if you want to do it the right way, keep reading.
A good practice is to always start each project in a unique virtual environment, for this the ideal is to use a venvs manager, what I like most is the anacoda/Conda which, besides being a venv manager is also a python package manager, a kind of "distribution".
If you had used this practice, then at the beginning of the development of the project you would create an env only with the version of python you would use in the project and, as you needed the libs would feed a file called requeriments.txt, then when it went to the production environment, just do:
pip install -r requirements.txt
Pipreqs:
If you didn’t do any of this and want to avoid the 'careless' way of solving the problem, let’s try to do a kind of "reverse engineering" with pipreqs
(although not yet the ideal form, but very close to it). With pipreqs you build your Requirements.txt based on your Mports, but automatically and not in the Olhometro, to do this just do:
# Instalando o pipreqs
$ pip install pipreqs
# Construindo o requirements.txt
$ pipreqs /path/projeto
INFO: Successfully saved requirements file in /path/projeto/requirements.txt
Pireqs works with Requirements.txt in your project directory, now simply include it in your installer and run pip install -r reqirements
at the facility.
Why did I say it’s not ideal that way? pq in the development environment (even considering a single virtual Nvironment) Voce may want to install some packages that are not needed in the production environment, so the ideal is to always work as virtualenvs, as "lean as possible" and manually add the libs in the requeriments.txt as you develop it.
Pipreqs has some interesting parameters, see:
$ pipreqs --help
pipreqs - Generate pip requirements.txt file based on imports
Usage:
pipreqs [options] <path>
Options:
--use-local Use ONLY local package info instead of querying PyPI
--pypi-server <url> Use custom PyPi server
--proxy <url> Use Proxy, parameter will be passed to requests library. You can also just set the
environments parameter in your terminal:
$ export HTTP_PROXY="http://10.10.1.10:3128"
$ export HTTPS_PROXY="https://10.10.1.10:1080"
--debug Print debug information
--ignore <dirs>... Ignore extra directories, each separated by a comma
--encoding <charset> Use encoding parameter for file open
--savepath <file> Save the list of requirements in the given file
--print Output the list of requirements in the standard output
--force Overwrite existing requirements.txt
Obs.
In both cases (in the correct or "careless" way) you will no longer need to "load" the library folder in the installation.
To learn more about the anaconda, see this answer here at Stopt.
Friend let me ask you, I’m in windows, and I’m trying to run pipreqs, I tried this way: python C: Python27 Lib site-Packages pipreqs pipreqs.py and it presents the following error: Import: cannot import name version
– Wictor Chaves
You don’t have Pip installed in windows? if you don’t have it, install it and use it to install the packages. That link can help you install Pip on windows.
– Sidon
I already installed pipreqs using Pip, but while trying to run from this error.
– Wictor Chaves
Dude... I haven’t been in touch with windows for a while, but theoretically it would have to be like linux, just give the command
pipreqs c:\path\projeto
. See if pipreqs is a binary (executable in windows), with the whereis command, if I’m not mistaken in windows iswhere
, try like thiswhere pipreqs
, if it is see if its path is in the path variable.– Sidon
In time: Consider using anaconda and end your package problems and their conflicts.
– Sidon