In the interest of not getting an XY problem: the goal is to create a virtual environment on synology dsm, so no apt-get, where pip is installed manually.
I am trying to create a virtual environment, in above environment (synology dsm package python 3.8 with pip installed manually).
However this gives the following error:
$ python3 -m venv new_venv
Error: Command '['/volume1/docker/builder/new_venv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
In the chain of finding that error I discovered that venv is working "just fine":
$ python3 -m venv --without-pip new_venv
Works as expected. Also pip itself works as expected. However I had to install pip manually. This also has as consequence that the synology dsm version of python does not have the module ensurepip..
# python3 -c "import ensurepip; print(ensurepip.__file__);"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'ensurepip'
This gives the problem: how does one manually install ensurepip, and/or make virtual env install pip without relying on ensurepip?
Install pip inside your venv virtual environment
Download the newest pip installation script and name the file get-pip.py:
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Create the virtual environment with Python 3 but without pip inside it (assuming you are in /volume1/docker/builder/):
$ python3 -m venv --without-pip /volume1/docker/builder/new_venv
Activate the virtual environment:
$ source /volume1/docker/builder/new_venv/bin/activate
Your prompt should now contain the virtual environment name in parens:
(new_venv) $
The script will install pip inside the activated venv virtual environment:
(new_venv) $ python get-pip.py
# or
(new_venv) $ python3 get-pip.py
Related
I am trying to install venv but getting this error:
name#malikov:~/Desktop/informtech$ python3 -m venv venv
Error: Command '['/home/name/Desktop/informtech/venv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
venv folder created but there is no activate file to activate venv
What should I do. Is there any solution. All problems started after upgrading python version from 3.8 to 3.10strong text
You can try installing venv for python3.10 via command:
sudo apt install python3.10-venv
First of all, this answer explains three python package locations nicely, I am giving a brief summary of them first, in my case for the azure-cosmos python package these are:
First, Global dist-packages, controlled with sudo apt-get (before installing a newer version with pip3 it shows ver 3.1.1):
$ sudo apt-get install python3-azure-cosmos
...
$ pip3 list -v | grep azure-cos
azure-cosmos 3.1.1 /usr/lib/python3/dist-packages
Second, Local dist-packages, installing with sudo pip3
$ sudo pip3 install -U azure-cosmos
...
$ pip3 list -v | grep azure-cos
azure-cosmos 4.2.0 /usr/local/lib/python3.8/dist-packages pip
Third, Local site-packages, (removed with sudo pip and then) installed with pip3 (without sudo)
$ sudo pip3 install -U azure-cosmos
...
$ pip3 list -v | grep azure-cos
azure-cosmos 4.2.0 /home/me/.local/lib/python3.8/site-packages pip
However, in all three cases my Python is looking ONLY in the (first) global dist-packages (that contains an older package version):
$ python3 -c "from azure.cosmos import CosmosClient"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'CosmosClient' from 'azure.cosmos' (/usr/lib/python3/dist-packages/azure/cosmos/__init__.py)
I do have $PATH and $PYTHONPATH set properly to include the local dist-packages and local site-packages locations, Python actually shows them in sys.path before global dist-packages:
$ python3 -c "import sys; print([p for p in sys.path])"
['', '/usr/local/lib/python3.8/dist-packages', '/home/me/.local/lib/python3.8/site-packages', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/usr/lib/python3/dist-packages']
So why is Python taking the old version of azure-cosmos that came with the distro instead of getting a newer version that I have installed with pip? What am I missing here?
(I did try to update the python3-azure-cosmos package but 3.1.1 seems to be highest available via apt-get, and that's not the point of the question)
An easy solution is to remove the GLOBAL dist-packages version, one can simply run:
$ sudo apt-get remove python3-azure-cosmos
Then Python magically uses a version from either local dist-packages or site-packages from my home dir (package installed via sudo pip3 or pip3 respectively), because the package does not exist in global dist-packages.
But... my problem is that I cannot run sudo in this case. So I cannot remove the global package. Halp.
Try to use the below command to Uninstall/Remove the packages without using sudo privileges
rm -rf <Package_Directory>
Linux rm -rf is a powerful command deletes directory forcefully. It means a file or directory will be removed. Even though it has read-only permission.
A possible workaround (but not a solution) to this and a similar issue I had one day later is to just use a python virtual environment, e.g. using pipenv:
$ pip3 install --upgrade pipenv
$ pipenv install azure-cosmos
$ pipenv run python -c "from azure.cosmos import CosmosClient"
And we have empty output so there is no import error anymore, meaning that it works.
I am trying to install Django in my windows 7 machine, as a prerequisite, I am installing virtualenvwrapper:
pip install virtualenvwrapper-win
But it throws the following error:
Error [WinError 87] The parameter is incorrect while executing command
python setup.py egg_info
Could not install packages due to an EnvironmentError: [WinError 87] The paramet
er is incorrect
[NOTE]:
Python version : Python 3.7.0b4
pip version: pip 10.0.1
Try using pyenv:
Step 1:
install virtualenv using pip
pip install virtualenv
Step 2
In a folder, open cmd and run:
python -m venv virtualenvname
eg:
python -m venv india
Step 3: Activate your Virtual environment by:
india\Scripts\activate
Note: S of sripts has to be in caps
Now you must see india before location in your cmd. If yes then your virtual env has been activated.
Something Like this:
(india) D:\dev\python\django\
pip3 -m venv yourprojectname
Are you trying my command. I got the error like you did with this command I got the problem
but, you can apply the following commands
py -m pip install --user virtualenv
py -m virtualenv env
OR
python3 -m pip install --user virtualenv
python3 -m virtualenv env
I'm trying to create a python virtualenv using anaconda python3.6 in ubuntu 16.04. Following https://docs.python.org/3/library/venv.html , I've tried
deploy#server:~/miniconda3/bin$ python3 -m venv ~/test
Error: Command '['/home/deploy/test/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
operating from the miniconda directory at ~/miniconda3/bin (screenshot). How can I this working?
edit:
deploy#server:~/miniconda3/bin$ /home/deploy/test/bin/python3 -Im ensurepip --upgrade --default-pip
/home/deploy/test/bin/python3: No module named ensurepip
If you are using anaconda, you should be using conda environments.
conda create --name test
For more information, see Managing Environments.
EDIT In response to OP wanting to use virtualenvs.
The error is with python not being able to find pip. You can get around this by installing it manually.
python3 -m venv test --without-pip
cd test
source bin/activate
curl https://bootstrap.pypa.io/get-pip.py | python3
At this point you will have a basic virtualenv with pip installed.
When I attempt to verify that Python3 can see Django by entering python3 followed by import django into the terminal (so I can print Django's version number), I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'django'
Python can detect Django if I enter python (followed by import django), but not python3. How can I correct this so Python3 can also detect Django?
These are the steps I took to install Django on my local machine:
Upgraded pip:
sudo -H pip3 install --upgrade pip
Downloaded and installed latest version of Python from binary.
Created project directory:
mkdir django-start && cd $_
Installed virtualenv:
pip3 install virtualenv
Created an environment:
virtualenv env
Activated the environment:
source env/bin/activate
Installed Django:
pip install django
You virtualenv is built for Python 2 environment. Cmd python3 in virtualenv is still using the global Python which doesn't have django.
So if you want to use Python 3 in virtualenv you should add the -p or --python argument when initialize the env:
virtualenv --python $(which python3) env
Mind you need remove your old Python 2 env folder before you run this command.