question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Special variable inside requirements.txt which contains path to current requirements.txt

See original GitHub issue

First of all i’m sorry for my poor English and pip skills What’s the problem this feature will solve? This feature request is based on my stackoverflow question https://stackoverflow.com/questions/57590215/path-to-current-file-inside-requirements-txt

Pip allow to specify path to other packages in requirements.txt. For example -e path/to/some/package. It allow pip users to reuse local packages between local projects

For example suppose i have following structure of folders:

my_collection_of_packages/
    package1/
        package1/
            some.py
        setup.py
        requirements.txt
    package2/
        same_structure_as_package1
        requirements.txt
project1/
    requirements.txt

package2 depends on package1, so package2/requirements.txt contains following string -e ../package1/. So if my projects depends on package2 i can perform something like pip install -e project2 and it will install package1 too. But unfortunately, it will not work if my project is not at the same folder level with my packages. For example, if my project is project1 and project1/requirements.txt contains -e ../my_collection_of_packages/package2/ it’s impossible to install package2/requirements.txt because it contains relative path ../package1/ which is equal project1/../package1/ if we run package2/requirements.txt.

Describe the solution you’d like From my point of view a special variable which contains path to current requirements.txt can be solution for this problem. I have no idea which name is better, but suppose it is ${requirements_pwd}. So now package2/requirements.txt can reference package1 by -e ${requirements_pwd}/../package1/ And project1 can reference package2 as -e ${requirements_pwd}/../my_collection_of_packages/package2/

Alternative Solutions It’s possible to achieve same result by using absolute paths, but this makes usage of packages on different machines almost impossible.

For linux another solution is to define environment variable ${package_collection} and use it inside requirements.txt. For example package2/requirements.txt should be ${package_collection}/my_collection_of_packages/package1/. Have no idea how to make it work on windows and linux simultaneously

Additional context Link to stackoverflow question: https://stackoverflow.com/questions/57590215/path-to-current-file-inside-requirements-txt

Thank in advance. Please let me know if something wrong with my problem statement.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pfmoorecommented, Aug 22, 2019

This might help clarify.

0reactions
Daivercommented, Aug 26, 2019

Hi @chrahunt ! Thank you for answer and thank you for suggestions! Actually currently i’m doing something very similar. But i want to avoid pip install -e package1;pip install -e package2;pip install -r requirements.txt because i use a lot of local packages with complicated dependencies. I need something like pip install -r local-requirements.txt which will collect all my local dependencies automatically. So currently i have a script which installs all local packages to project’s venv. But it’s temporal solution. I’m totally agree that hard-coded relative paths is terrible, but i just cannot figure out other solution. Currently manual download is not an issue for me because i keep all packages in monorepository.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pip freeze creates some weird path instead of the package ...
I use pip freeze > requirements.txt to add the required package into the requirement.txt file. However, I realized that some of the packages, ......
Read more >
User Guide - pip documentation v22.3.1
using the environment variable PIP_USER_AGENT_USER_DATA to include a JSON-encoded string in the user-agent variable used in pip's requests. Requirements Files#.
Read more >
Create Your requirements.txt Using This Technique
The most common technique to create a requirements.txt file is to run pip freeze > requirements.txt when all packages are already installed. However,...
Read more >
How to install Python packages with pip and requirements.txt
Put requirements.txt in the directory where the command will be executed. If it is in another directory, specify its path like ...
Read more >
How to Create Requirements.txt File in Python - Javatpoint
Since you have not used the requirement.txt file, it may be possible that your application will not run properly or even not get...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found