-
-
Notifications
You must be signed in to change notification settings - Fork 15.1k
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
Difficulty using pip in a venv #71178
Comments
At risk of adding noise to this issue, I can confirm that |
@FRidh Sure that this is a “question” instead of a “bug”? |
@scoates Another way to work around the bug, that doesn't require to patch anything is to call |
Yes, this is not a Nixpkgs bug. Python packaging in Nixpkgs covers building expressions using Nix, and not generating impure environments. |
Is this a problem with pip itself? I thought it was with nix packaging, but I could be wrong, I suppose. It's not like pip's |
I'm also experiencing this and I can confirm that @mawis' hotfix works. |
To add more context to this: it seems to me, that this is related to the following change in PIP: pypa/pip#7061 What I still don't get is why this change is present in pythonPackage*.pip on NixOS 19.09 which is still on version 19.2.3 – while this change was introduced in upstream not before version 19.3. |
because the pip of the venv is used |
or is that the same one as the nixpkgs one? |
@FRidh That might be an explanation. I must admit, that I have no idea how all that gets resolved. I'm no Python developer. |
@mawis : your fixes worked for me too. But I'm just as curious how my pip/virtualenv setup wasn't "pinned" and suddenly started failing? I even pinned the nix channel. So, before, this worked: nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixpkgs-19.03-darwin.tar.gz -p python37 python37Packages.virtualenv python37Packages.pip
virtualenv --no-setuptools test
test/bin/pip and now, it doesn't. Same error as you. And same workaround. I thought one of the main points of NixOS, particularly with pinned channel, was reproducibility? I'm dying to know what changed here overnight. |
@mawis: By the way, for me, simply removing |
Same issue with |
I think it's a problem with nix, that breaks It can be repeated easily by running:
You can see that nix |
Do not use There is an issue with |
@FRidh : how does this explain something that was previously working (and pinned with a channel) stopped working? Isn't that the whole point of nix? Or is there some special code inside those nix packages that auto-downloads a newer version of pip or the like? |
In case it's immediately useful to anyone, I have this in one of my bootstrap scripts (on MacOS at least), to fix this problem: sed -i -e's/pip._internal.main/pip._internal/' `nix-shell --run 'pipenv run which pip'` |
This appears to be where this is discussed upstream: pypa/pip#7209 |
What commit and is there a fix coming? Me using |
pipenv is fixed in 7f63ecf. |
New pipenv fix #71800. I do not see anything more actionable in this ticket. As I explained, by using |
for my personal venv use, i need to do:
so that the install packages appear on the PYTHONPATH |
same issue additionally can say:
previously I could execute python without nix-shell just from virtualenv location by path (And did so from ide (maybe need to swith to nix-build)) |
I have yet to see a reproducible example here that is not using |
Current status: seems to be fixed for me after a bunch of updates, and changing my Example with import <nixpkgs> {};
stdenv.mkDerivation rec {
name = "sample-dev";
env = buildEnv { name = name; paths = buildInputs; };
buildInputs = [
(python37.withPackages (pypkgs: [ pypkgs.pip pypkgs.virtualenv ]))
pipenv
(buildEnv { name = "python-packages-bin-only"; paths = [
awscli
]; })
];
shellHook = ''
# set SOURCE_DATE_EPOCH so that we can use python wheels
SOURCE_DATE_EPOCH=$(date +%s)
'';
} Another vote to close this issue, here, from me. |
Can anyone who knows Nix explain, why, even with a pinned channel[1], this broke? Isn't the whole point of nix to make things deterministic? How could nix be downloading a new version of a package that is broken? I would imagine the pinning of the channel locks packages as they were at the time. Appreciate any help. [1] #71178 (comment) |
@silviogutierrez If you're using PIP your installing code that you don't get it from Nix but from PyPI. PyPI does not provide a reproducible build. At any moment you will just install the latest version of the PythonPackage available at PyPI. |
also pointing to a channel is not pinning, because the channel is a moving target. To pin you need to point to a specific revision. |
@mawis , that helps, and is sort of what I suspect. But I would imagine pip itself is bundled in the |
@silviogutierrez (this is Little Snitch showing what's happening) |
@scoates : interesting! I never would have imagined that. Of course pip itself goes out to Pypi to install packages, but I never thought virtualenv itself needed to hit the internet to start a new virtualenv to get python/pip. That seems very odd. But! I just turned off the internet entirely, and (I could just go through the virtualenv code, but this process of deduction is just as interesting) silviogutierrez@Silvios-MacBook-Pro (testing): time virtualenv with-internet
Using base prefix '/nix/store/jd8200285gwy8p538hrd2wpwfnm5b27r-python3-3.7.4'
New python executable in /Users/silviogutierrez/Sites/silviogutierrez/joyapp.com/testing/spam/bin/python3.7
Also creating executable in /Users/silviogutierrez/Sites/silviogutierrez/joyapp.com/testing/spam/bin/python
Installing setuptools, pip, wheel...
done.
real 0m4.238s
user 0m2.904s
sys 0m0.738s silviogutierrez@Silvios-MacBook-Pro (testing): time virtualenv without-internet
Using base prefix '/nix/store/jd8200285gwy8p538hrd2wpwfnm5b27r-python3-3.7.4'
New python executable in /Users/silviogutierrez/Sites/silviogutierrez/joyapp.com/testing/bar/bin/python3.7
Also creating executable in /Users/silviogutierrez/Sites/silviogutierrez/joyapp.com/testing/bar/bin/python
Installing setuptools, pip, wheel...
done.
real 0m25.969s
user 0m2.547s
sys 0m0.708s |
@silviogutierrez We're getting way off topic, here, so I suggest this be the last of these comments, but you can supply |
In case someone comes here confused, some notes I took on how to use virtualenv on nix/nixos: Python virtualenvUsing plain virtualenv / pip on nix / nixosFrom: Installing pip in the nix environment prevent proper virtualenv creation. Also, one should not create the virtual env using the The following { nixpkgs ? import <nixpkgs> {}
}:
with nixpkgs;
stdenv.mkDerivation rec {
name = "python-virtualenv-shell";
env = buildEnv { name = name; paths = buildInputs; };
buildInputs = [
python3
python3Packages.virtualenv
# It is essential **not** to add `pip` here as
# it would prevent proper virtualenv creation.
];
shellHook = ''
# set SOURCE_DATE_EPOCH so that we can use python wheels
SOURCE_DATE_EPOCH=$(date +%s)
'';
} An example of using this nix shell and virtualenv / pip: $ touch shell.nix
# ..
# Write paste the above nix code into the 'shell.nix' file
# using an editor of your choice.
$ editor shell.nix
# Enter the nix shell which should bring the python interpreter and
# the virtualenv executable.
$ nix-shell
$ virtualenv venv
Using base prefix '/nix/store/c2n0xp0j3nacr1l17lmrdzwp16ljsvll-python3-3.7.5'
New python executable in /home/myuser/dev/mypiptest/venv/bin/python3.7
Also creating executable in /home/myuser/dev/mypiptest/venv/bin/python
Installing setuptools, pip, wheel...
done.
$ source ./venv/bin/activate
(venv)
$ which python
/home/myuser/dev/mypiptest/venv/bin/python
(venv)
$ which pip
/home/myuser/dev/mypiptest/venv/bin/pip
(venv)
$ pip install ipython
# ..
(venv)
$ which ipython
/home/myuser/dev/mypiptest/venv/bin/ipython
(venv)
$ echo "request" > requirements.txt
(venv)
$ pip install -r requirements.txt
# ..
(venv)
$ ipython
Python 3.7.5 (default, Oct 14 2019, 23:08:55)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.10.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import request
In [2]:
exit
(venv)
$ |
@jraygauthier : years later, I took another stab at getting rid of virtualenv and using the built in And yet inside nix, Turns out, it was because I had |
Describe the bug
I'm using
pip
inside adefault.nix
on NixOS 19.09 as well as on the docker containernixos/nix:latest
. I had a working setup that usedpip
to install the packagenrfutils
. In the last build on my CI server 11 days ago everything worked as expected. When I trigger a rebuild it's now failing with the following message:To Reproduce
Save the following file as
default.nix
and startnix-shell
:Expected behavior
I would expect a shell in which pip installed the program
nrfutil
.Additional context
I found out that I can fix the problem with either one of these two:
pip install nrfutil
I can callpython2.7 -m pip install nrfutil
.After starting the shell
.venv/bin/pip
contains:It works if I change this to:
(The change is from
pip._internal.main
topip._internal
.)Metadata
"x86_64-linux"
Linux 4.19.79, NixOS, 19.09.809.5000b1478a1 (Loris)
yes
yes
nix-env (Nix) 2.3
"nixos-19.09.809.5000b1478a1, unstable-19.09pre192418.e19054ab3cd"
"home-manager-19.03"
/nix/var/nix/profiles/per-user/root/channels/nixos
Maintainer information:
The text was updated successfully, but these errors were encountered: