-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Package with pyproject.toml cannot be installed with pip install -e #564
Comments
@erzoe Please don't run the In general, it's best to run To troubleshoot, can you share the output of the following commands?
|
Thank you for your fast reply. Here is the output of the requested commands:
|
Yeah, that |
Sorry, but I don't understand why I should install it in a virtual environment. Virtual environments are great for testing that the software works with other versions of python and other packages but this is the version that I want to use always (1) because I want to find the bugs that I am adding asap and (2) because I need the functionality that I am adding asap. I guess I could install it in a virtual environment and start that virtual environment when I boot up my computer but then what's the point in the virtual environment? |
@erzoe I think the main issue with installing packages in a global Python environment is that there could be conflicts between their dependencies. For example, if Also, the system Python environment is carefully constructed by your OS distributor (e.g. Debian) to provide the Python packages used by the OS and its packaged tools. So, it's best to heed the "permission denied" errors and leave that alone. Your idea to create a "personal" virtual environment would address the second issue, but only partially address the first issue, because conflicts could still arise. An excellent tool that solves both issues is pipx, which handles creating isolated virtual environments and putting any command line scripts on your Further reading: https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/ |
Thank you for the information. Pipx seems to work fine. Thanks to your links I have also found this other interesting article on What to do when you botch a release on PyPI which might come in handy someday (well, hopefully not). Nevertheless I am still going without a pyproject.toml file to avoid that error message because—as you have pointed out yourself—it tempts users to run pip with sudo which is in my experience more dangerous than installing a package outside of a virtual environment. But I am now showing how to install the program using pipx in my readme and have added a note that installing python packages outside of a virtual environment is discouraged and a link to your comment. Also, it seems inconsistent if editable mode installs fail where normal installs work just fine. |
Pip is supposed to apply |
Ahh, it could be because of the editable mode install. Pip might assume any user who knows enough to use an editable install will also know to use Technically, system python distributions are not intended to have any pip installs in them - those are for system installs only (apt, apk, yum, etc). Even upgrading pip is unsupported. |
@erzoe I agree with @henryiii: you should be using More useful reading: https://snarky.ca/what-the-heck-is-pyproject-toml/ |
@henryiii no,
so pip recognizes correctly that
|
It's not that I am opposed to using I looked at another project where I knew that this error message did not occur and noticed the difference was the existence of the When I started using pip I, I did not know about On the other hand I have never experienced any problems with installing packages outside of virtual environments. (Although it's probably fair to mention that I have started using virtual environments after I learned about them and I knew that I would only need the package in a limited context and for a limited time, like for a university project. Maybe that has saved my some trouble.) If pip gave a concise error message, one or two lines explaining that you should run that command inside of a virtual environment that would be ok. But with the error as it is I want to make sure that none of my users is accidentally running into it. |
It seems there is the possibility to avoid that error message while still having a import site
import os
site.ENABLE_USER_SITE = os.geteuid() != 0 I have found that variable in this issue. |
Are your users downloading your git source, then running If you want to suggest a better error message for pip, that's probably something you could request (check first to make sure no one already made the request).
That's the point of sudo. It means you know what you are doing and take responsibility for breaking stuff.
Yep, that's why. You should never install to the system site packages, so if user site packages are disabled, you have a completely locked down system, no installs allowed. System Pythons were not intended for users to mess with. They were intended to run system scripts and support system packages. Feel free to ask the packagers, they will tell you the one and only way to distribute Python packages is to make apt/yum/etc. packages, and pip should not be used. 🤦 That's why virtual environments are useful - they give you something you can edit, with an easy revert (delete the venv) and they manage to share the binary part of Python (so they are easy to setup). I'd think your OS disabling user site packages is a mistake, you could look into why that was done. It's obviously pushing people toward sudo installs, which is much worse. |
I'd guess this would install to the user location, but since it's globally disabled, no one would be able to use it after it's installed? |
Debian does not disable user site-packages, I am sure there is something more to understand why this happens. |
Most users will just run
So this is the wrong place to do that? Then I'll take a look at the pip repository.
no, running the program is possible. |
I assume you can run things in
Then I'd include this in the contributor documentation, and I think that's fine. If someone knows enough to start running |
Your contributors should create a virtual environment. The documentation should recommend that they do so. That setuptools attempts a root install after a user install fails is definitely not something that should happen. I'd have suggested to report it to setuptools but everything installation-related in setuptools is deprecated and the only time you'd be exposed to setuptools performing an install is through |
and
work, too |
Another idea is to use nox (or tox) for contributors; you can control the experience, and users get a virtual environment created for them. See https://scikit-hep.org/developer/tasks for some examples. You pay a little setup cost but get free environment management and reproducibility. That's weird, so user site packages are supposed to be enabled in Debian, and seem to be enabled in Debian, but are being reported as not enabled. |
Have you considered trying PyPA/Flit? :) |
@layday yes, I am showing in my readme how to install with pipx and am saying that "It is discouraged to install python packages outside of a virtual environment."
Thank you very much for your comment. That explains the inconsistent behavior. If it's deprecated anyway I guess it does not make much sense to open a new issue. |
Huh, a lot of stuff to look into. This is my first time publishing something on PyPI so there are a lot of new things to learn. Haven't done much else this week ^^" No, thus far I have only ever used pip, switched to pipx today, but I'll take a look at them eventually. |
There's a guide for flit at https://scikit-hep.org/developer/pep621. I've tried to get something like this into packaging.python.org in pypa/packaging.python.org#1031 - but a few people don't want that in until setuptools supports PEP 621 configuration, and they don't want to push Flit, even if it avoids these sorts of problems for new users. :'( |
pip is an installer, but the suggestion to use flit is about changing your build tool (from setuptools) 🙂 |
ok, so pipx works fine for running the code but breaks the tests because obviously the imports don't work anymore. With this simple [tox]
envlist = py3
[testenv]
commands =
python -m unittest discover -s tests I can run my tests simply by calling I think I've finally got everything running now. Thank you for your help! |
I'd highly recommend pytest over unittest - unittest mostly exists for Python's own test suite, but pretty much everyone else likely should use pytest. You don't even have to change your tests at first, you can just run unittest with pytest and get nicer features and reporting. See https://henryiii.github.io/level-up-your-python/notebooks/3.1%20PyTest.html :) Yes, Nox or Tox are ideal for this sort of testing and tasks, though. :) |
thanks for the tip, that looks good |
FYI, the relevant bug tracking the user site editable installation error is pypa/setuptools#3019 and the fix (pypa/setuptools#3151) is released in setuptools 62.0.0 |
OS version
Debian 11
Python version
Python 3.9.2
Pip version
pip 21.3.1
Guide link
https://packaging.python.org/en/latest/tutorials/packaging-projects/
Problem description
I have created an example project as explained in Packaging Python Projects with the following pyproject.toml file:
and setup.cfg:
Also I have added a setup.py because I need to include data files:
When I am trying to install the package with
pip install -e .
I am getting the error message listed in the next section.Removing pyproject.toml resolves the problem. But does it cause other problems that I am missing right now?
Error message
The text was updated successfully, but these errors were encountered: