Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python

James White
James White
6,159 Points

Error installing virtualenv as --user

When I run

pip3 install --user virtualenv

I get the error:

 ~/python-projects  pip3 install --user virtualenv                                                                                                                                                  [45/53]
Collecting virtualenv
Downloading virtualenv-12.1.1-py2.py3-none-any.whl (1.6MB)
100% |████████████████████████████████| 1.6MB 262kB/s
Installing collected packages: virtualenv
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.4/site-packages/pip-6.1.1-    py3.4.egg/pip/basecommand.py", line 246, in main
  status = self.run(options, args)
File "/usr/local/lib/python3.4/site-packages/pip-6.1.1-    py3.4.egg/pip/commands/install.py", line 352, in run
  root=options.root_path,
File "/usr/local/lib/python3.4/site-packages/pip-6.1.1-    py3.4.egg/pip/req/req_set.py", line 693, in install
  **kwargs
File "/usr/local/lib/python3.4/site-packages/pip-6.1.1-    py3.4.egg/pip/req/req_install.py", line 817, in install
  self.move_wheel_files(self.source_dir, root=root)
File "/usr/local/lib/python3.4/site-packages/pip-6.1.1-    py3.4.egg/pip/req/req_install.py", line 1018, in move_wheel_files
  isolated=self.isolated,
File "/usr/local/lib/python3.4/site-packages/pip-6.1.1-py3.4.egg/pip/wheel.py", line 138, in move_wheel_files
  name, user=user, home=home, root=root, isolated=isolated
File "/usr/local/lib/python3.4/site-packages/pip-6.1.1-py3.4.egg/pip/locations.py", line 236, in distutils_scheme
  i.finalize_options()
File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/command/install.py", line 251, in finalize_options
  raise DistutilsOptionError("can't combine user with prefix, "
 distutils.errors.DistutilsOptionError: can't combine user with prefix, exec_prefix/home, or install_(plat)base

When I run pip3 install virtualenv. I get no errors. Any reason not to go this route?

6 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

I'm assuming that homebrew's Python 3 has a set prefix, an alternate place to install libraries (probably inside of Cellar). That's conflicting with --user, as you can see from the error message.

Python 3.3+ has a nice venv package already available that you could just use in the same way as virtualenv. You'd do python -m venv my_venv where my_venv is the name of the virtualenv you want to create. You do the activating step the exact same way.

James White
James White
6,159 Points

I just installed Python3 using Homebrew. The most recent version is 3.4. So should I just be using pyenv-3.4 instead of virtualenv?

James White
James White
6,159 Points

I kinda did what you suggested but I'm using python 3.4. And I had to use pyenv-3.5 to create then activated the same way.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Why did you have to use pyenv-3.5? Python 3.4 definitely has the venv module and it works with exactly the command I gave before.

James White
James White
6,159 Points

Well, I was following this (https://robinwinslow.co.uk/2013/12/26/python-3-4-virtual-environment/) before I got your answer. I didn't have to install it though, I guess it came with Python3.

James White
James White
6,159 Points

And python -m venv my_env creates the same directory structure as pyenv-3.4 including the pyvenv.cfg file.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

OK. I just haven't come across the pyenv command for creating virtualenvs before, I guess.

I mean, I use pyenv to have more than one Python installed but that's about it.

James White
James White
6,159 Points

I also mistyped the name of the command earlier. :(

I didn't use pyenv. I used pyvenv-3.4.