Skip to content
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

Using PIP_NO_CACHE_DIR raises exception #2897

Closed
rhcarvalho opened this issue Jun 11, 2015 · 13 comments
Closed

Using PIP_NO_CACHE_DIR raises exception #2897

rhcarvalho opened this issue Jun 11, 2015 · 13 comments
Labels
auto-locked Outdated issues that have been locked by automation

Comments

@rhcarvalho
Copy link

This is related to #2855 and #2856.
#2856 fixed the exception when using --no-cache-dir flag, but using the equivalent env var still doesn't work:

$ PIP_NO_CACHE_DIR=1 pip install gunicorn
Exception:
Traceback (most recent call last):
  File "/usr/lib/python3.3/site-packages/pip-7.0.3-py3.3.egg/pip/basecommand.py", line 223, in main
    status = self.run(options, args)
  File "/usr/lib/python3.3/site-packages/pip-7.0.3-py3.3.egg/pip/commands/install.py", line 242, in run
    with self._build_session(options) as session:
  File "/usr/lib/python3.3/site-packages/pip-7.0.3-py3.3.egg/pip/basecommand.py", line 71, in _build_session
    if options.cache_dir else None
  File "/usr/lib64/python3.3/posixpath.py", line 82, in join
    elif not path or path.endswith(sep):
AttributeError: 'int' object has no attribute 'endswith'
@dstufft
Copy link
Member

dstufft commented Jun 24, 2015

I think you want PIP_NO_CACHE_DIR=off.

@rhcarvalho
Copy link
Author

Thanks for your reply, @dstufft.

$ PIP_NO_CACHE_DIR=off pip install gunicorn
Collecting gunicorn
  Downloading gunicorn-19.3.0-py2.py3-none-any.whl (110kB)
    100% |████████████████████████████████| 110kB 1.7MB/s 
Installing collected packages: gunicorn
Successfully installed gunicorn-19.3.0

However, what does "no cache dir = off" mean? I understand it means to use the cache dir... so I double check that it is caching:

$ PIP_NO_CACHE_DIR=off PIP_CACHE_DIR=the-cache pip install django
Collecting django
  Downloading Django-1.8.2-py2.py3-none-any.whl (6.2MB)
    100% |████████████████████████████████| 6.2MB 91kB/s 
Installing collected packages: django
Successfully installed django-1.8.2
$ tree the-cache/
the-cache/
└── http
    ├── 1
    │   └── d
    │       └── 6
    │           └── 4
    │               └── 5
    │                   └── 1d64584e92602feb17a86d9818a6020c216c9a04bcf58fb91c2f5a13
    └── c
        └── d
            └── 1
                └── 5
                    └── 9
                        └── cd159833e45a286ff17af3902a2d935061be9d24f93f9b256bca9387

11 directories, 2 files

But what I want is to disable the cache... and that doesn't work still:

$ PIP_NO_CACHE_DIR=on pip install gunicorn
Traceback (most recent call last):
  File "/home/rodolfo/.virtualenvs/tmp-151361bc365703be/bin/pip", line 11, in <module>
    sys.exit(main())
  File "/home/rodolfo/.virtualenvs/tmp-151361bc365703be/lib/python2.7/site-packages/pip/__init__.py", line 217, in main
    return command.main(cmd_args)
  File "/home/rodolfo/.virtualenvs/tmp-151361bc365703be/lib/python2.7/site-packages/pip/basecommand.py", line 219, in main
    timeout=min(5, options.timeout)) as session:
  File "/home/rodolfo/.virtualenvs/tmp-151361bc365703be/lib/python2.7/site-packages/pip/basecommand.py", line 71, in _build_session
    if options.cache_dir else None
  File "/home/rodolfo/.virtualenvs/tmp-151361bc365703be/lib64/python2.7/posixpath.py", line 70, in join
    elif path == '' or path.endswith('/'):
AttributeError: 'int' object has no attribute 'endswith'

IIRC PIP_NO_CACHE_DIR=on is equivalent to PIP_NO_CACHE_DIR=true and PIP_NO_CACHE_DIR=1 (what I had in the original issue description).

@dstufft
Copy link
Member

dstufft commented Jun 25, 2015

PIP_NO_CACHE_DIR=off disables the cache, it's a confusing option that happens that way because of the way we automatically translate cli flags into environment variables.

@rhcarvalho
Copy link
Author

Oh, so then in the presence of both PIP_NO_CACHE_DIR=off and PIP_CACHE_DIR=the-cache, setting the cache-dir takes precedence and makes pip cache downloaded packages?

@gst
Copy link

gst commented Jul 28, 2015

I was having, right now, the same exception with the same backtrace but without specifying any of these env variables.
But I was having the failure from time to time .. I could launch "pip install -r requirements.txt" 3 times in a row and don't get the failure, and on the 4th time it'd occur.. or any combination of failure/success .. :s

I put a pdb.set_trace at the line 82 and could see that effectively the path value was 1 (the int, not the str).. after verify of my pip settings I've seen I had in my pip.conf : "no-cache-dir = true" ; changed it to "no-cache-dir = off" and there it's good..

But why was it failing sometimes and sometimes not :-?

@rhcarvalho
Copy link
Author

Tested this again on a temporary virtualenv, seems that all positive values (1, true, on, yes) for PIP_NO_CACHE_DIR cause the same error, while negative values (0, false, off, no) cause no errors, but I still couldn't verify whether the cache is disabled or enabled when I use PIP_NO_CACHE_DIR=0. Isn't it the same as not specifying the variable at all?!

$ pip list
pip (8.1.2)
setuptools (12.0.5)
(tmp-368ff30f354a8052) ✔ ~/openshift/src/github.com/openshift/source-to-image [master|…5⚑ 4] 
22:34 $ PIP_NO_CACHE_DIR=1 pip install gunicorn
Exception:
Traceback (most recent call last):
  File "/home/rodolfo/.virtualenvs/tmp-368ff30f354a8052/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/home/rodolfo/.virtualenvs/tmp-368ff30f354a8052/lib/python2.7/site-packages/pip/commands/install.py", line 249, in run
    with self._build_session(options) as session:
  File "/home/rodolfo/.virtualenvs/tmp-368ff30f354a8052/lib/python2.7/site-packages/pip/basecommand.py", line 69, in _build_session
    if options.cache_dir else None
  File "/home/rodolfo/.virtualenvs/tmp-368ff30f354a8052/lib64/python2.7/posixpath.py", line 70, in join
    elif path == '' or path.endswith('/'):
AttributeError: 'int' object has no attribute 'endswith'
Traceback (most recent call last):
  File "/home/rodolfo/.virtualenvs/tmp-368ff30f354a8052/bin/pip", line 11, in <module>
    sys.exit(main())
  File "/home/rodolfo/.virtualenvs/tmp-368ff30f354a8052/lib/python2.7/site-packages/pip/__init__.py", line 221, in main
    return command.main(cmd_args)
  File "/home/rodolfo/.virtualenvs/tmp-368ff30f354a8052/lib/python2.7/site-packages/pip/basecommand.py", line 251, in main
    timeout=min(5, options.timeout)) as session:
  File "/home/rodolfo/.virtualenvs/tmp-368ff30f354a8052/lib/python2.7/site-packages/pip/basecommand.py", line 69, in _build_session
    if options.cache_dir else None
  File "/home/rodolfo/.virtualenvs/tmp-368ff30f354a8052/lib64/python2.7/posixpath.py", line 70, in join
    elif path == '' or path.endswith('/'):
AttributeError: 'int' object has no attribute 'endswith'
$ PIP_NO_CACHE_DIR= pip install gunicorn
Requirement already satisfied (use --upgrade to upgrade): gunicorn in /home/rodolfo/.virtualenvs/tmp-368ff30f354a8052/lib/python2.7/site-packages
$ PIP_NO_CACHE_DIR=0 pip install gunicorn
Requirement already satisfied (use --upgrade to upgrade): gunicorn in /home/rodolfo/.virtualenvs/tmp-368ff30f354a8052/lib/python2.7/site-packages

@asobrien
Copy link

If you explicitly want pip to use a cache-dir (e.g., PIP_NO_CACHE_DIR={1,true,on,yes}) then a cache-dir must be explicitly set as well (e.g., PIP_CACHE_DIR=/tmp/). The exception that is raised in the absence of the cache-dir option stems from here: https://github.com/pypa/pip/blob/master/pip/basecommand.py#L67

Note that, pip uses falsy values to enable boolean options like --no-compile and --no-cache-dir (https://pip.pypa.io/en/stable/user_guide/?highlight=falsy#configuration)

@rhcarvalho
Copy link
Author

@asobrien thank you very much. I'm closing this as a usage error, thanks for pointing out the docs.

@brechtm
Copy link

brechtm commented Dec 15, 2016

For what it's worth, I'd like to say that is very confusing behaviour. Setting PIP_CACHE=0 to disable the cache would make sense, but having to set PIP_NO_CACHE_DIR=0 to enable no-cache-dir is just ludicrous.

thuandt pushed a commit to inspectorioinc/docker-python that referenced this issue Mar 9, 2018
yajo added a commit to Tecnativa/doodba that referenced this issue Apr 9, 2018
Since Werkzeug's version is hardcoded to a lower one in every Odoo supported version and fork, the easiest patch is to install it as odoo user, which will take precedence over the version installed by automated tools.

Took the chance to use `$PIP_NO_CACHE_DIR=0` as explained in pypa/pip#2897 (comment) instead of adding `--no-cache-dir` everywhere.

Fix #19
yajo added a commit to Tecnativa/doodba that referenced this issue Apr 10, 2018
Since Werkzeug's version is hardcoded to a lower one in every Odoo supported version and fork, the easiest patch is to install it as odoo user, which will take precedence over the version installed by automated tools.

Took the chance to use `$PIP_NO_CACHE_DIR=0` as explained in pypa/pip#2897 (comment) instead of adding `--no-cache-dir` everywhere.

Fix #19
@jakirkham
Copy link
Contributor

After going through this recently, have to agree that how these environment variables are set is very strange. It would be nice to see them fixed to be a bit more intuitive.

@pradyunsg
Copy link
Member

After going through this recently, have to agree that how these environment variables are set is very strange. It would be nice to see them fixed to be a bit more intuitive.

I agree - could you file a new issue (or is there an existing one) for this, so that we can discuss this properly in a separate issue?

@jakirkham
Copy link
Contributor

Thanks @pradyunsg for the encouragement. Sorry for the delay. Have raised issue ( #5735 ).

@lock
Copy link

lock bot commented Jun 2, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jun 2, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation
Projects
None yet
Development

No branches or pull requests

7 participants