Pip installation in virtualenv broken - python

I get this error from the virtualenv's pip installation:
➜ myproject git:(master) ✗ pyenv/bin/pip --help
Failed checking if argv[0] is an import path entry
ValueError: character U+6e657970 is not in range [U+0000; U+10ffff]
Fatal Python error: no mem for sys.argv
ValueError: character U+6e657970 is not in range [U+0000; U+10ffff]
Current thread 0x00007fff767c5000 (most recent call first):
[1] 10941 abort pyenv/bin/pip --help
The virtual env's python works, the system python and pip work (all python3).

Turns out that virtualenv hard links the python executable to the system python, so that when I upgraded python, it got out of line with the virtual env's pip installation.
Posting here for other to find, in case this happens to them.
Solution is to wipe the pyenv folder, and reinstall a fresh virtualenv (if you've been using a requirements.txt file, this is what the virtual env is designed to do!

According to the pip documentation, you can install pip in a virtual environment by typing the following command when your virtual environment is activated:
python -m ensurepip --upgrade
For your information, ensurepip is an in-built Python module that serves the purpose of installing pip in your Python environment.
This solution can be used if you do not want to start a fresh new virtual environment and you want to retain your dependencies

First, try updating pip
pip install --upgrade pip
if this does not fix it, I would try uninstalling pip and then reinstall.
to remove try:
sudo pip uninstall pip
then install again.
pip install -U pip setuptools
also i am assuming your are using linux or mac. on windows commands differ.

Related

Mac M1 python packages error after upgrade to python3

I am writing a project in NativeScript and I received the following error the last few days when I tried the commands: ns run ios or ns doctor.
Couldn't retrieve installed python packages.
The Python 'six' package not found.
I tried python and pip upgrade and also the command pip install six.
Nothing of them fixed the problem.
I believe that is not a NativeScript issue, is about the configuration of the python packages in my machine. I mention that I am using a MacBook with M1 chip and it is running the 12.5 OS version.
I will appreciate any suggestions on this situation.
Lastly, I found the solution. It was about the python folder into the path /usr/local/bin/python
You could check it by the following command: where python
In my case this folder is missing, perhaps I deleted it after the upgrade of the python3.
That was a mistake both folders should exist on this path!
If you type: where python you should receive: /usr/local/bin/python
If you type: where python3 you should receive: /usr/local/bin/python3
In order to fix the error, I installed python again by using the brew install pyenv
this suggestion helps me to install it properly.
In the end, in order to eliminate all errors I installed the Python six package by using the command:
pip install --ignore-installed six
Try doing it with the python virtual environment. Following are the steps.
Create a virtual environment.
Activate the virtual environment.
Run the pip install command with the virtual environment active.
Implement as follows:
use correct version of Python when creating VENV
python3 -m venv venv
activate on Unix or MacOS
source venv/bin/activate
activate on Windows (cmd.exe)
venv\Scripts\activate.bat
activate on Windows (PowerShell)
'venv\Scripts\Activate.ps1'
install the required package in the virtual environment
python3 -m pip install --upgrade pip
python3 -m pip install six
Note: This works only when you are in the virtual environment.

Error in installing venv for python3 on mac

While installing a virtual environment by running the following command on terminal:
python3 -m pip install --user venv
I'm encountering the following error:
ERROR: Could not find a version that satisfies the requirement venv
ERROR: No matching distribution found for venv
Please help me with this! I believe since default python is version 2.x in macOS I must try installing virtualenv but I require venv.
You cannot install venv with pip: venv is a module from the standard library since Python 3.3. So you don't need to install it, just start using:
python3 -m venv path/to/new-venv
Venv doesn't exists. I guess that you might want the package virtualenv.
Venv is commonly used as the name of virtual environment created by virtualenv.
So, the command is:
python3 -m pip install --user virtualenv
python3 -m virtualenv venv

Command "python3 -m pip install [...]" failed with error code 1 in None

I am trying to install the PyInstaller module for python through the terminal on my mac, and it is not working.
I am trying to install this module so I can package a program. I have tried to install through terminal through different commands (e.g. "pip install pyinstaller), but it is not working, even though I know I have PIP correctly installed.
When trying to install, I type, python3 -m pip install pyinstaller.
The result is Command "/usr/local/bin/python3 -m pip install --ignore-installed --no-user --prefix /private/var/folders/w5/rlzrygt57j3c3nl4p29d2djc0000gw/T/pip-build-env-mjrd7sir https://files.pythonhosted.org/packages/b2/86/095d2f7829badc207c893dd4ac767e871f6cd547145df797ea26baea4e2e/setuptools-41.2.0-py2.py3-none-any.whl#sha256=4380abcf2a4ffd1a5ba22d687c6d690dce83b2b51c70e9c6d09f7e8c7e8040dc https://files.pythonhosted.org/packages/00/83/b4a77d044e78ad1a45610eb88f745be2fd2c6d658f9798a15e384b7d57c9/wheel-0.33.6-py2.py3-none-any.whl#sha256=f4da1763d3becf2e2cd92a14a7c920f0f00eca30fdde9ea992c836685b9faf28" failed with error code 1 in None
I have upgraded PIP, and tried using sudo python3 -m pip install pyinstaller, but I am not in the sudoers file.
Please help
Create a virtual environment for your project in your project directory.
python3 -m venv env
source env/bin/activate
Test which python is activated
which python
This will show that your local python in the virtualenv you just created is now the current python
Try installing now using
pip install pyinstaller
This ought to work for you. Always use virtual environments for your projects instead of installing system wide libraries unless you really need to set this up for the system.

How to force install package in virtualenv?

Trying to install django with different version that in system, it shows me:
Installing collected packages: Django
Found existing installation: Django 1.7.11
Not uninstalling django at /home/user/lib/python2.7, outside environment /home/user/webapps/v2_dev/venv
Successfully installed Django-1.8.19
But in fact there is old version
tried with different commands:
./venv/bin/pip install Django==1.8.11
pip install Django==1.8.11
UPDATED:
When I install my packages it shows:
The required version of setuptools (>=16.0) is not available,
and can't be installed while this script is running. Please
install a more recent version first, using
'easy_install -U setuptools'.
(Currently using setuptools 3.1 (/home/user/lib/python2.7/setuptools-3.1-py2.7.egg))
When I do the upgrade:
venv/bin/pip install --upgrade setuptools
Requirement already up-to-date: setuptools in ./venv/lib/python2.7/site-packages (40.5.0)
I arrived at this post while looking for how to force install something in a virtualenv despite it being already installed in the global python. This happens when the virtual env was created with --system-site-packages.
In this situation, for certain packages it may be important to have a local version within the virtualenv, even if for many other packages we can share the global versions. This is the case of pytest, for example. However, pip will refuse to install a package in the virtualenv if it can already find the most recent version in the system site.
The solution is to use pip install --ignore-installed mypackage.
Instead of installing setuptools and Django like ./venv/bin/pip install ..., try to activate your virtual environment first and install the stuff you need afterwards.
Activating virtual environment:
Go to the folder where your virtual environment is located (typically the root folder of your project) and type one of the two:
source venv/bin/activate (Unix-based systems)
venv\Scripts\activate (Windows)
This will ensure that you are not mixing packages installed in different environments.
Forcing reinstall of the packages:
Simple upgrade can be done by adding: --upgrade or -U
Forcing reinstall of the packages can be done by adding: --force-reinstall
In your case (once the environment is activated):
python -m pip install -U --force-reinstall setuptools Django
Step by step:
Deactivate and delete the old virtual environment
Create new environment using python -m virtualenv venv (python 2) or python -m venv venv (python 3)
python above is the interpreter which you want to use in your project. That's the only point where you might want to use for example python3 or some absolute path instead. Later use the code as is.
source venv/bin/activate
Activating the virtual environment
python -m pip install -U pip
If you have issue with ImportError: No module named _internal than probably you are using an old version of pip. Issue is described here
python -m pip install -U --force-reinstall -r requirements.txt
-U --force-reinstall is a bit of an overkill in case of fresh environment, but it will do no harm
Go to the place where your manage.py is located and start the server using python manage.py runserver
The problem was in Webfaction VPS
Need an empty file named sitecustomize.py in the /home/username/webapps/appName/env/lib/python2.
That empty file overrides their python customizations, one of which is to include any packages in the ~/lib/python2.7 directory.
You might need to deactivate your virtual env and activate it again for changes to take effect.
workaround but it works!
in your virtualenv directory change the properties of the pyvenv.cfg file
include-system-site-packages = True
this will cause the packages installed on the main to be used

How do I can install pip inside virtual environment

I have created one virtual-environment. Inside that I have to install few python packages. For that I need pip package inside virtual environment. How can I install pip inside virtual-environment?
According to the pip documentation, you can install pip in a virtual environment by typing the following command when your virtual environment is activated:
python -m ensurepip --upgrade
For your information, ensurepip is an in-built Python module that serves the purpose of installing pip in your Python environment.
you can also try with upgrading pip command even after no pip installed at you specified virtual location
python -m pip install --upgrade pip
This will give you an error as below but also install latest pip version on virtual location
Can't uninstall 'pip'. No files were found to uninstall.
Successfully installed pip-19.2.3
kindly try above option and let me in case any issue.
Usually, you install pip OUTSIDE of your virtual environment.
But after activating the virtualenv you just run "pip install" inside the environment.
Meaning, you install it outside the virtualenv.
You run "pip install" inside the virtualenv.
You can follow this useful guide:
http://docs.python-guide.org/en/latest/dev/virtualenvs/
When you create a virtual environment for a particular python revision installed in your computer, all the libraries currently installed in your python revision would be copied inside the virtual environment.
Pip is usually default available in your python revision directory.
If not, install it first in your original python install directory.
Then copy the pip.exe to the virtual environment's Scripts directory.
After that execute the below command from your terminal (this is for Windows):
\your_venv_directory_path\Scripts\pip.exe install --upgrade pip
Now you can just type
pip install --upgrade pip
and it should recognise the path to the pip.exe file inside your venv
when creating the virtual-environment, be sure to include pip in the command. e.g:
conda create -n my_env pip python=3.6.8
I would suggest deleting the venv and recreating it using the above command

Categories