How to install virtualenv scripts to /usr/bin - python

I install virtualenv with command sudo /usr/bin/pip-2.6 install virtualenv
And it says
Requirement already satisfied (use --upgrade to upgrade):
virtualenv in /usr/local/lib/python2.6/dist-packages
Cleaning up...
Why pip from /usr/bin looks to /usr/local/lib?
I need to install virtualenv scripts directly to /usr/bin, so I write
sudo /usr/bin/pip-2.6 install --install-option="--install-scripts=/usr/bin" virtualenv
But again it responds with
Requirement already satisfied (use --upgrade to upgrade):
virtualenv in /usr/local/lib/python2.6/dist-packages
Cleaning up...
Adding --upgrade doesn't help.
How can I install virtualenv scripts to /usr/bin ?

For your current issue can you first uninstall virtualenv using pip, and then reinstall using --script-dir=DIR, -s DIR as an --install-option.
As for your issue running pip with extra arguments and install not seeming to do anything, that may be fixed on develop branch at https://github.com/pypa/pip if not please file a bug with us on the GitHub issue tracker for pip.
As to why it is behaving like this - the install is based on the python installation not on the location of pip. Pip uses setuptools/distribute under the hood and conforms to the configuration of the python it is running under.
You can see where the version of python you are using installs to by running it - in this case probably python2.6 and querying the sys module.
>>> import sys
>>> sys.prefix
>>> sys.exec_prefix
See also distutils.sysconfig
For more information:
Installing Python Modules
setuptools
distribute

Try:
sudo /usr/bin/pip-2.6 install --install-option="--prefix=/usr/bin" virtualenv
(source).

Related

pip with default python version OSX

I'm trying to write a script that uses speedtest-cli, I have installed the module with pip install speedtest-cli. If I run pip install speedtest-cli I get the following
Requirement already satisfied: speedtest-cli in /usr/local/lib/python2.7/site-packages
If I try to use pip with the default python, as recommended by another answer here, like so python -m pip install speedtest-cli I get
/usr/bin/python: No module named pip
I figured that the pip is setup for one of the other versions of python but the only version of python in /usr/local/bin is python3 and in /usr/bin there is python, python2.6, and python2.7 but I have tried defining each ones of those as the interpreter at the top of the file and none of them works, each producing giving the same import error on the speedtest module.
Which version of python is pip linked to then, or why is the installed module not importing?
The easiest solution was to completed a fresh start.
Remove all references to easy_install, python, and pip using the following;
rm -r easy_install*
rm -r pip*
rm -r python*
Then I used this guide to properly install, setup, and configure python with HomeBrew, with pip and virtualenv installed.
The article is fairly lengthy so I'm not going to copy it all out here but here is an image snapshot in case the link goes dead.

Can't install Pip Packages in El Capitan (10.11)

Okay, so I have brew, and I've brew reinstalled python since El Capitan.
MacBook-Pro-2:decipher Alex$ which python
/usr/local/bin/python
MacBook-Pro-2:decipher Alex$ whereis python
/usr/bin/python
I have two pythons. That's all well and good. Brew doctor is clean, except for some Unbrewed header files were found in /usr/local/include, none of which seem related to Python. Short of virtualenv, is there any way to install packages anymore? I feel like I might be missing something.
Just like this guy I was trying to get IPython. I don't really need it, so I gave up the other day. Now I need Pylint. If I try to install it with pip:
IOError: [Errno 13] Permission denied: '/lib/python2.7/site-packages/logilab_common-1.1.0-py2.7-nspkg.pth'
Does anyone know how to point pip towards another instance of python on my system, or do something else so I can have the old behavior back? Please?
-- EDITS --
Suggested was the idea of using /usr/local/bin/pip to install ipython. This is the output. I can't figure out how to use ipython still.
MacBook-Pro-2:MNIST Alex$ /usr/local/bin/pip install ipython[all]
Requirement already satisfied (use --upgrade to upgrade): ipython[all] in /Library/Python/2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): traitlets in /usr/local/bin (from ipython[all])
Requirement already satisfied (use --upgrade to upgrade): pickleshare in /usr/local/bin (from ipython[all])
Requirement already satisfied (use --upgrade to upgrade): simplegeneric>0.8 in /usr/local/bin (from ipython[all])
... the rest of the requirements are all satisfied in usr/local/bin
I had trouble too with El Capitan. I did these things and it worked:
1) Install Homebrew
2) Install Python 3 with Homebrew
3) In terminal enter these installs (in this order)
$ pip3 install pyobjc-core
$ pip3 install pyobjc
$ pip3 install pillow
$ pip3 install pyautogui
To point pip to another Python instance of your system, you need to use pip from the same bin/ folder where python is installed so it resolves to the same site-packages.
Example:
/usr/local/bin/pip install logilab_common
To make /usr/local/ writable by a local user on OSX do:
sudo chown -R `whoami`:admin /usr/local/*
More information
http://blog.blakesimpson.co.uk/read/89-fix-homebrew-error-usr-local-bin-is-not-writable-on-os-x-el-capitan
As Mikko Ohtamaa points out in the comments, somehow, I had a version of python in a folder called /lib. I'm not sure how it got there. I think that's the version of python I was using. Once I just sudo rm -rf /lib everything suddenly worked.

Control the pip version in virtualenv

How do I control the version of pip which is used in a freshly created venv?
By default, it uses a vendored pip distribution which may be out of date or unsuitable for whatever other reason. I want to be able to create a venv with a user-specified version of pip installed initially, as opposed to creating one and then upgrading the pip installation from within the env.
For me, I just upgraded pip/virtualenv/virtualenvwrapper on my machine (not inside the virtualenv). Subsequently created virtualenvs had the updated version.
deactivate
pip install --upgrade pip virtualenv virtualenvwrapper
mkvirtualenv ...
From reading the source of virtualenv, it looks like pip is installed from a source tarfile included with virtualenv. In virtualenv 1.10.1, it is pip-1.4.1.tar.gz in the site-packages/virtualenv_support directory (it gets setuptools from the same place). You could feasibly replace that archive to control the version; virtualenv.py, at least the version I have, doesn't care which version of pip is there:
if not no_pip:
install_sdist('Pip', 'pip-*.tar.gz', py_executable, search_dirs)
You could also pass the --no-pip option and then install the version you want from source.
In virtualenv 1.11, it looks for a wheel file (e.g. pip-*.whl) instead of a tar.gz, but other than that it acts the same way (thanks #wim for the update).
You cannot downgrade pip using pip, the solution is to install a specific version in your virtual environment:
virtualenv env -p python3.6 --no-pip
source env/bin/activate
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py pip==18.1
This will allow you to keep using --process-dependency-links that was removed in pip 19.
It's easy enough to replace the pip that gets installed in your virtual environment. Within your virtual environment active, simply execute the following command:
pip install pip==1.4.1
Since Python 3.9 the stdlib venv module has EnvBuilder.upgrade_dependencies. Unfortunately, it has two shortcomings:
Won't really help users to install a specific pip version, only the latest.
It still installs the vendored pip and setuptools versions first, and then uninstall them if they're outdated, which they almost always will be in practice.
It would be ideal to install the latest versions directly! The venv CLI provides a --without-pip argument that is useful here. You can use this to opt-out of the vendored pip, and then actually use the vendored pip wheel to install your desired pip version instead (along with any other packages you might want in a freshly created virtual environment).
It's best to put it into a function - this goes into your shell profile or rc file:
function ve() {
local py="python3"
if [ ! -d ./.venv ]; then
echo "creating venv..."
if ! $py -m venv .venv --prompt=$(basename $PWD) --without-pip; then
echo "ERROR: Problem creating venv" >&2
return 1
else
local whl=$($py -c "import pathlib, ensurepip; [whl] = pathlib.Path(ensurepip.__path__[0]).glob('_bundled/pip*.whl'); print(whl)")
echo "boostrapping pip using $whl"
.venv/bin/python $whl/pip install --upgrade pip setuptools wheel
source .venv/bin/activate
fi
else
source .venv/bin/activate
fi
}
As written, this function just pulls latest pip, setuptools, and wheel from index. To force specific versions you can just change this line of the shell script:
.venv/bin/python $whl/pip install --upgrade pip setuptools wheel
Into this, for example:
.venv/bin/python $whl/pip install pip==19.3.1
For Python 2.7 users, you may do a similar trick because virtualenv provides similar command-line options in --no-pip, --no-setuptools, and --no-wheel, and there is still a vendored pip wheel available to bootstrap since Python 2.7.9. Pathlib will not be available, so you'll need to change the pathlib usage into os.path + glob.
While creating virtual environment using venv module, use optional argument --upgrade-deps.
That will upgrade pip + setuptools to the latest on PyPI.
Example : python3 -m venv --upgrade-deps .venv
Reference link :
venv module documentation
It indicates "Changed in version 3.9: Add --upgrade-deps option to upgrade pip + setuptools to the latest on PyPI"
Note : I tried this using Python 3.10.4
Solved the same issue today on my windows machine with python 3.10.2 installed.
download required pip wheel from history to path\to\python\lib\ensurepip\bundled
in path\to\python\lib\ensurepip\__init__.py change _PIP_VERSION = your version
create environment as usual python -m venv path\to\env
I had issues with pip 22.3.1, so I wanted to downgrade it to 22.3, while pip 22.3.1 produces errors and not letting me downgrade as the other solutions suggest.
I solved the issue by creating a new venv with the specific pip version, as follows:
virtualenv env -p python3.10 --pip 22.3
TLDR
python -m pip install --upgrade pip==<target version number>
Example
Downgrading from pip 20.3 to pip 19.3 from within a virtual environment.
(env) $ pip --version
pip 20.3.1
(env) $ python -m pip install --upgrade pip==19.3 # downgrading
Collecting pip==19.3
Using cached pip-19.3-py2.py3-none-any.whl (1.4 MB)
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 20.3.1
Uninstalling pip-20.3.1:
Successfully uninstalled pip-20.3.1
Successfully installed pip-19.3
(env) $pip --version trex#Tobiahs-MacBook-Pro
pip 19.3

pip won't install Python packages locally with --user

I'm trying to install packages locally with pip. It used to work with --user but now when I try it, it finds the version of the package in /usr/local/lib/ and then does not install it locally. Normally it would install things in ~/.local but now it just checks the system-wide dir for the package and if it's there, it does not install it (which is not what I want) and if it's not there, it tries to install it in /usr/local/lib which I do not have write permissions at. Eg:
$ pip install --user rpy2
Requirement already satisfied (use --upgrade to upgrade): rpy2 in /usr/local/lib/python2.7/dist-packages/
How can I make pip install --user always go to ~/.local and not a system-wide directory?
Citing Marcus Smith (maintainer of pip):
If you think the global site is out of date, and want the latest in
the user site, then use:
pip install --upgrade --user SomePackage
If the global site is up to date, and you really just want the same
thing duplicated in --user, then use:
pip install --ignore-installed --user SomePackage (which works correctly now after the merge of #1352, which is to be released in v1.5)
How can I make pip install --user always go to ~/.local and not a system-wide directory?
Use both --upgrade and --ignore-installed arguments.
According to the pip documentation, that syntax is correct, but requires Python 2.6.
User Installs
With Python 2.6 came the “user scheme” for installation, which means
that all Python distributions support an alternative install location
that is specific to a user. The default location for each OS is
explained in the python documentation for the site.USER_BASE variable.
This mode of installation can be turned on by specifying the –user
option to pip install.
Moreover, the “user scheme” can be customized by setting the
PYTHONUSERBASE environment variable, which updates the value of
site.USER_BASE.
To install “SomePackage” into an environment with site.USER_BASE
customized to ‘/myappenv’, do the following:
export PYTHONUSERBASE=/myappenv
pip install --user SomePackage
So the following entry should work for you:
export PYTHONUSERBASE=~/.local
pip install --user rpy2
installing any package using user command
for upgrading pip :
python -m pip install --upgrade --user pip

Python packages not installing in virtualenv using pip

I'm having trouble installing twisted
pip --version
pip 1.1 from
/home/chris/GL/GLBackend/glenv/lib/python2.7/site-packages/pip-1.1-py2.7.egg
(python 2.7)
Create a virtual environment
chris#chris-mint ~/GL/GLBackend $ sudo virtualenv -p python2.7 glenv
Running virtualenv with interpreter /usr/bin/python2.7 New python
executable in glenv/bin/python2.7 Also creating executable in
glenv/bin/python Installing
distribute.............................................................................................................................................................................................done.
Installing pip...............done.
Just in case, I'll enable all permissions
chris#chris-mint ~/GL/GLBackend $ sudo chmod -R 777 glenv
chris#chris-mint ~/GL/GLBackend $ source glenv/bin/activate
(glenv)chris#chris-mint ~/GL/GLBackend $ pip freeze
argparse==1.2.1 distribute==0.6.24 wsgiref==0.1.2
twisted is not listed here as installed
(glenv)chris#chris-mint ~/GL/GLBackend $ sudo pip install twisted
Requirement already satisfied (use --upgrade to upgrade): twisted in
/usr/local/lib/python2.7/dist-packages Requirement already satisfied
(use --upgrade to upgrade): zope.interface>=3.6.0 in
/usr/local/lib/python2.7/dist-packages (from twisted) Requirement
already satisfied (use --upgrade to upgrade): distribute in
/usr/local/lib/python2.7/dist-packages (from
zope.interface>=3.6.0->twisted) Cleaning up... (glenv)chris#chris-mint
~/GL/GLBackend $ pip uninstall twisted Cannot uninstall requirement
twisted, not installed Storing complete log in
/home/chris/.pip/pip.log
But when I install it it says that its already installed.
Force the install:
sudo pip install -I twisted
Downloading/unpacking twisted Downloading Twisted-12.3.0.tar.bz2
(2.6Mb): 2.6Mb downloaded Running setup.py egg_info for package
twisted
. . .
Successfully installed twisted zope.interface distribute Cleaning
up...
And yet it still isn't installed
(glenv)chris#chris-mint ~/GL/GLBackend $ pip freeze
argparse==1.2.1 distribute==0.6.24 wsgiref==0.1.2
**When I try running Python scripts which use twisted, I get an error saying that twisted is not installed. That is:
ImportError: No module named twisted.python**
The problem here is that you're using sudo when you shouldn't be. And that's causing pip to try to install into /usr/local/lib instead of ~/glenv/lib. (And, because you used sudo, it's successfully doing so, but that doesn't help you, because you're not allowing system site-packages in your venv.)
There are multiple reasons sudo pip could lead to this behavior, but the most likely is this: On most systems (including the various Mac and RHEL/CentOS boxes I have immediate access to), the sudoers file will reset your environment, then add back in a handful of whitelisted environment variables. This means that when you sudo pip, it will not see the environment variables that virtualenv sets up, so it will fall back to doing the default thing and install into your system Python, instead of your venv.
But really, it doesn't matter why this is happening. The answer is the same: just do pip install instead of sudo pip install.
Note that you also want to remove the sudo on the virtualenv call, as this will probably cause the venv to be set up incorrectly (which is why you need the sudo chmod, which wouldn't be necessary otherwise). The whole point of installing things under your user home directory is that you can do it with your normal user permissions.
As a side note, you also may want to upgrade to a newer virtualenv/pip, as 1.8 and 1.2 have some bug fixes and improvements. But I verified that I get exactly the same problem as you even with the latest (1.8.4 and 1.2.1) versions, so I don't think that's relevant here.
The sudo pip is causing the problem here. It will install the package in your system instead of the virtual environment you created. So when it says the requirement is already satisfied. Try to look add the directory it is pointing to. Which is in your case, while you were trying to install, was /usr/local/lib/python2.7/dist-packages
If it's inside something like /usr/local/lib/..., which does not points to your virtualenv folder then it is installed in your system. Otherwise, in correct scenario it will look something like this /usr/local/lib/..../<name of your virtualenv>/lib.
You can always use commands like which python & which pip to see if they both are using the placeholder of our virtual environment.

Categories