0

I am learning how to use venv here: https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/#installing-from-source

And it says I can install a source package by:

python3 -m pip install .

Which works, but now if I do pip freeze then I see:

my-package @ file:///Users/joesmith/my-package

The problem is if I export this to a requirements.txt and try to install this environment on another machine then it won't work cause the path to source changed obviously.

What is the proper way to use a source package locally like i did but also export it afterwards so that another person can recreate the environment/run the code on another machine?

guy
  • 1,021
  • 2
  • 16
  • 40

2 Answers2

1

You would install package from PyPI rather than from source.

i.e. pip install requests

In this way other developers will also easily run your project.

Kholdarbekov
  • 973
  • 1
  • 10
  • 28
1

Pip has support for VCS like git. You can upload your code to git (e.g. Github, Gitlab, ..) for example and then use the requirements.txt. like this:

git+http://git.example.com/MyProject#egg=MyProject

https://pip.pypa.io/en/stable/cli/pip_install/#vcs-support

Kerrim
  • 485
  • 4
  • 9
  • I need to manually add this line to the requirements.txt? That seems error-prone.... – guy Jun 02 '21 at 14:07
  • 1
    @guy you can do: `pip install git+http://git.example.com/MyProject#egg=MyProject` and then `pip freeze`. If you can't host it publicly you can add credentials to your git via url if supported (e.g. in github): `git+http://username:password@git.example.com/MyProject#egg=MyProject` – Kerrim Jun 02 '21 at 19:09