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

virtualenv will pick up a [install] settings in setup.cfg for installing pip #740

Closed
sabaini opened this issue Apr 3, 2015 · 9 comments
Closed

Comments

@sabaini
Copy link

sabaini commented Apr 3, 2015

I happened to have a setup.cfg in a directory that I've installed a virtualenv from (ie. the cwd contained the setup.cfg). To my surprise, virtualenv picked up on the [install] section and wanted to install pip into the prefix mentioned there.

Testcase:

$ cat > setup.cfg <<EOF
[install]
prefix = /nosuchdirectory
EOF
$ virtualenv venv     
New python executable in venv/bin/python
Installing setuptools, pip...
  Complete output from command /home/peter/tmp/tst/venv/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip:
  Ignoring indexes: https://pypi.python.org/simple
Collecting setuptools
Collecting pip
Installing collected packages: pip, setuptools

  Exception:
  Traceback (most recent call last):
    File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-6.0.8-py2.py3-none-any.whl/pip/basecommand.py", line 232, in main
      status = self.run(options, args)
    File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-6.0.8-py2.py3-none-any.whl/pip/commands/install.py", line 347, in run
      root=options.root_path,
    File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-6.0.8-py2.py3-none-any.whl/pip/req/req_set.py", line 549, in install
      **kwargs
    File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-6.0.8-py2.py3-none-any.whl/pip/req/req_install.py", line 754, in install
      self.move_wheel_files(self.source_dir, root=root)
    File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-6.0.8-py2.py3-none-any.whl/pip/req/req_install.py", line 963, in move_wheel_files
      isolated=self.isolated,
    File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-6.0.8-py2.py3-none-any.whl/pip/wheel.py", line 234, in move_wheel_files
      clobber(source, lib_dir, True)
    File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-6.0.8-py2.py3-none-any.whl/pip/wheel.py", line 176, in clobber
      os.makedirs(dest)
    File "/home/peter/tmp/tst/venv/lib/python2.7/os.py", line 150, in makedirs
      makedirs(head, mode)
    File "/home/peter/tmp/tst/venv/lib/python2.7/os.py", line 150, in makedirs
      makedirs(head, mode)
    File "/home/peter/tmp/tst/venv/lib/python2.7/os.py", line 150, in makedirs
      makedirs(head, mode)
    File "/home/peter/tmp/tst/venv/lib/python2.7/os.py", line 157, in makedirs
      mkdir(name, mode)
  OSError: [Errno 13] Permission denied: '/nosuchdirectory'

----------------------------------------
...Installing setuptools, pip...done.
Traceback (most recent call last):
  File "/usr/local/bin/virtualenv", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 825, in main
    symlink=options.symlink)
  File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 993, in create_environment
    install_wheel(to_install, py_executable, search_dirs)
  File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 961, in install_wheel
    'PIP_NO_INDEX': '1'
  File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 903, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /home/peter/tmp/tst/venv/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip failed with error code 2

$ virtualenv --version
12.0.7
@petroav
Copy link

petroav commented Oct 14, 2015

I've run into this issue as well. Is there a workaround?

@crquan
Copy link

crquan commented Dec 21, 2015

hit by the same issue, and in the created virtualenv trying to pip install something also failed of above prefix not exist, or no write permission;
workaround is to cd into some other directory where is no setup.cfg with [install] section; but why virtualenv needs to read setup.cfg ?

@dkasak
Copy link

dkasak commented Jan 9, 2016

Just had an hour of head-scratching over this. To make matters worse, I had the prefix set to a dot directory so it wasn't even immediately obvious virtualenv was creating junk. This is definitely a bug or at least counterintuitive behaviour.

@jaraco
Copy link
Member

jaraco commented Jan 3, 2019

This issue also causes problems if setup.cfg has a syntax error. Consider:

draft $ cat > setup.cfg                                                                                                                                                                  
garbage
draft $ virtualenv env                                                                                                                                                                   
Using base prefix '/Library/Frameworks/Python.framework/Versions/3.7'
New python executable in /Users/jaraco/draft/env/bin/python3
Also creating executable in /Users/jaraco/draft/env/bin/python
Installing setuptools, pip, wheel...Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/bin/virtualenv", line 11, in <module>
    sys.exit(main())
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/virtualenv.py", line 712, in main
    symlink=options.symlink)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/virtualenv.py", line 947, in create_environment
    download=download,
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/virtualenv.py", line 904, in install_wheel
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/virtualenv.py", line 796, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /Users/jaraco/draft/env/bin/python3 - setuptools pip wheel failed with error code 2

  Complete output from command /Users/jaraco/draft/env/bin/python3 - setuptools pip wheel:
  Looking in links: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages, /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/virtualenv_support, /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/virtualenv_support
Collecting setuptools
  Using cached https://files.pythonhosted.org/packages/37/06/754589caf971b0d2d48f151c2586f62902d93dc908e2fd9b9b9f6aa3c9dd/setuptools-40.6.3-py2.py3-none-any.whl
Collecting pip
  Using cached https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl
Collecting wheel
  Using cached https://files.pythonhosted.org/packages/ff/47/1dfa4795e24fd6f93d5d58602dd716c3f101cfd5a77cd9acbe519b44a0a9/wheel-0.32.3-py2.py3-none-any.whl
Installing collected packages: setuptools, pip, wheel
Exception:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/virtualenv_support/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/basecommand.py", line 228, in main
    status = self.run(options, args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/virtualenv_support/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/commands/install.py", line 335, in run
    use_user_site=options.use_user_site,
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/virtualenv_support/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/req/__init__.py", line 49, in install_given_reqs
    **kwargs
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/virtualenv_support/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/req/req_install.py", line 748, in install
    use_user_site=use_user_site, pycompile=pycompile,
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/virtualenv_support/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/req/req_install.py", line 961, in move_wheel_files
    warn_script_location=warn_script_location,
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/virtualenv_support/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/wheel.py", line 216, in move_wheel_files
    prefix=prefix,
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/virtualenv_support/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/locations.py", line 153, in distutils_scheme
    d.parse_config_files()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 406, in parse_config_files
    parser.read(filename)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/configparser.py", line 696, in read
    self._read(fp, filename)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/configparser.py", line 1079, in _read
    raise MissingSectionHeaderError(fpname, lineno, line)
configparser.MissingSectionHeaderError: File contains no section headers.
file: 'setup.cfg', line: 1
'garbage\n'
----------------------------------------
...Installing setuptools, pip, wheel...done.

I encountered this issue in tox-dev/tox-venv#25 when invoking install_wheel. Probably virtualenv should perform some sort of isolation in install_wheel, probably by passing cwd='/' to call_subprocess(). At least that's what pre-commit does.

@stale
Copy link

stale bot commented Apr 3, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Just add a comment if you want to keep it open. Thank you for your contributions.

@stale stale bot added the wontfix label Apr 3, 2019
@cunderwood-va
Copy link

This still occurs.

@ericholscher
Copy link

Just hit this as well. Would be useful if we could at least pass a flag or something to virtualenv to ignore it. I think we're likely just going to end up doing a mv setup.cfg setup.cfg.bak && virtualenv, which isn't a great solution :)

@gaborbernat
Copy link
Contributor

Does pip have a flag to ignore it's config files?

@gaborbernat gaborbernat added this to the 20.0.0 milestone Dec 23, 2019
@gaborbernat gaborbernat modified the milestones: 20.0.0, 20.1.0 Jan 21, 2020
@gaborbernat
Copy link
Contributor

Fixed with #1641 on python 2 👍

@pypa pypa locked and limited conversation to collaborators Jan 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants