I am trying to build a container using the docker official python:3.6.8 image that will encapsulate a python package I am developing along with its dependencies. The idea is to supply the container with the code repository using the ADD mypkg.tar.gz /pytmp/mypkg directive then create a virtualenv and install mypkg from within this env, then output the corresponding site-packages directory to share it later.
My Dockerfile first gets virtualenv through apt-get then creates the dummy environment and tries to install the package before zipping site-packages:
RUN cd /pytmp && \
virtualenv -p /usr/local/bin/python3 venv && \
source venv/bin/activate && \
pip install -v mypkg
RUN cd /pytmp/venv/lib/python3.6/ && \
zip -r /python_packages.zip site-packages/
Under my system (ubuntu 18.04), I can do a working pip install . from mypkg root directory. But inside the container, the install fails with error
ERROR: Could not find a version that satisfies the requirement mypkg (from versions: none)
ERROR: No matching distribution found for mypkg
Is pip looking for mypkg on pypi ? Is there something wrong with my instructions ?
I am using a setup.cfg-only scheme. The setup.cfg contains the following
[options]
packages = find_namespace:
package_dir =
=src
install_requires=
numpy
pyspark
sklearn
pylint
pre-commit
[options.extras_require]
test = pytest
docs = Sphinx; sphinx-rtd-theme
[options.packages.find]
where=src
Thanks for your help !
CodePudding user response:
It's probably failing because you're pointing it at a thing that looks like a package name, rather than like a directory. Make sure you're doing pip install /actual/path/to/your/package, with a slash at end at least, might need full path, as right now it's going to try to install from PyPI.
However: you really shouldn't be distributing site-packages. For libraries, just distribute your tarball. If you're distributing an application, the full Docker image might work, or you can use PyInstaller, or other tools (https://pythonspeed.com/articles/distributing-software/ has a survey).
