Pip default behavior conflicts with virtualenv?

2024/11/20 20:37:37

I was following this tutorial

When I got to virtualenv flask command, I received this error message:

Can not perform a '--user' install. User site-packages are not visible in this virtualenv.

This makes sense as the point of virtualenv is to create a new environment which you can control, and the --user command places everything in a specific location, defeating the objective of separation of dev environment.

It seems like pip defaults to --user installations though, can I change this default behavior? And, even better, can I get pip to play nice with virtualenv at all times?

To clarify, here is what my terminal looks like.

MELCHIOR:miguelgrinberg-microblog megablanc$ virtualenv flask
New python executable in flask/bin/python
Installing setuptools, pip, wheel...Complete output from command /Users/megablanc/Dev...log/flask/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel:Can not perform a '--user' install. User site-packages are not visible in this virtualenv.
----------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):File "/Users/megablanc/Library/Python/2.7/bin/virtualenv", line 11, in <module>sys.exit(main())File "/Users/megablanc/Library/Python/2.7/lib/python/site-packages/virtualenv.py", line 832, in mainsymlink=options.symlink)File "/Users/megablanc/Library/Python/2.7/lib/python/site-packages/virtualenv.py", line 1004, in create_environmentinstall_wheel(to_install, py_executable, search_dirs)File "/Users/megablanc/Library/Python/2.7/lib/python/site-packages/virtualenv.py", line 969, in install_wheel'PIP_NO_INDEX': '1'File "/Users/megablanc/Library/Python/2.7/lib/python/site-packages/virtualenv.py", line 910, in call_subprocess% (cmd_desc, proc.returncode))
OSError: Command /Users/megablanc/Dev...log/flask/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel failed with error code 1
Answer

You don't need to set the --user flag. After you create your virtualenv (virtualenv flask), activate it: source flask/bin/activate. Your shell should look something like (flask) ~>.

Once your virtualenv is activated, you should be able to pip install packages without issue. For example, pip install numpy. They'll be installed in: lib/python2.6/site-packages/ (for whatever version of Python you are using)

https://en.xdnf.cn/q/26280.html

Related Q&A

How to update user password in Django Rest Framework?

I want to ask that following code provides updating password but I want to update password after current password confirmation process. So what should I add for it? Thank you.class UserPasswordSeriali…

ImportError: No module named xlrd

I am currently using PyCharm with Python version 3.4.3 for this particular project.This PyCharm previously had Python2.7, and I upgraded to 3.4.3.I am trying to fetch data from an Excel file using Pand…

How do I automatically fix lint issues reported by pylint?

Just like we have "eslint --fix" to automatically fix lint problems in Javascript code, do we have something for pylint too for Python code?

Conversion from JavaScript to Python code? [closed]

Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines. It is not currently accepting answers.We don’t allow questi…

connect to a DB using psycopg2 without password

I have a postgres database on my localhost I can access without a password$ psql -d mwt psql (8.4.12) Type "help" for help.mwt=# SELECT * from vatid;id | requester_vatid |...-----+---------…

Shebang doesnt work with python3

I have the following program:#!/usr/local/bin/python3print("Hello")Via terminal I do test.py and I get:Traceback (most recent call last):File "/usr/lib/python3.3/site.py", line 629,…

Why does pip freeze list pkg-resources==0.0.0?

On Ubuntu 16.04 with virtualenv 15.0.1 and Python 3.5.2 (both installed with apt) when I create and activate new Python virtual environment withvirtualenv .virtualenvs/wtf -p $(which python3) --no-site…

How to delete an instantiated object Python?

I am relatively new to object oriented programming and I cannot figure out how to delete an instantiated object in Python. if self.hit_paddle(pos) == True or self.hit_paddle2(pos) == True:bar = bar + 1…

Call method from string

If I have a Python class, and would like to call a function from it depending on a variable, how would I do so? I imagined following could do it:class CallMe: # Classdef App(): # Method one...def Foo(…

Scipy sparse... arrays?

So, Im doing some Kmeans classification using numpy arrays that are quite sparse-- lots and lots of zeroes. I figured that Id use scipys sparse package to reduce the storage overhead, but Im a little …