Problem while installing virtualenv on AWS Ubuntu 18.04 AMI - python

How to install virtualenv properly on AWS Ubuntu 18.04 AMI. I have tried various ways such as through pip and through apt-get but I am not able to either properly install or configure it. Whenever I am running command virtualenv --python=python3.6 .venv or virtualenv --version it is giving me this error:
ERROR:root:failed to read config file /home/ubuntu/.config/virtualenv/virtualenv.ini because PermissionError(13, 'Permission denied')
How to properly install and configure virtualenv?

First check if Python3 is installed
apt list installed | grep -i python3
After that
python3 -m venv my_app/env

Related

how to create a virtual env with snap installed python38

Using snap I installed python38 on an Ubuntu 18 server. now I want to create a new virtual environment but I fail as these commands fail:
virtualenv --python /snap/bin/python38 myvenv
Running virtualenv with interpreter /snap/bin/python38
python3.8: can't open file '/usr/lib/python3/dist-packages/virtualenv.py': [Errno 2] No such file or directory
test -f /usr/lib/python3/dist-packages/virtualenv.py; echo "it exists!"
# OUTPUT: it exists!
# --------------------------------------------------------------------------------
python38 -m venv myvenv
The virtual environment was not created successfully because ensurepip is not
available. On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.
apt-get install python3-venv
You may need to use sudo with that command. After installing the python3-venv
package, recreate your virtual environment.
Failing command: ['/tmp/myvenv/bin/python3.8', '-Im', 'ensurepip', '--upgrade', '--default-pip']
This is my first experience with snap, and I'm unsure how I can install python3-venv to make it work.
Any help would be appreciated

ModuleNotFoundError: No module named 'virtualenv.seed.embed.via_app_data' when I created new env by virtualenv

I was creating a new virtual environment on Ubuntu 20.04:
$ virtualenv my_env
But it gave an error:
ModuleNotFoundError: No module named 'virtualenv.seed.embed.via_app_data'
Other info:
$ virtualenv --version
virtualenv 20.0.17 from /usr/lib/python3/dist-packages/virtualenv/__init__.py
#yushulx
I also ran into the same issue. I installed both via pip3 and via sudo apt install python3-virtualenv and it gave me an error but after I ran pip3 uninstall virtualenv I could create a virtualenv without issue
Try to create the virtual environment using directly venv module
python3 -m venv my_env
To fix this on Ubuntu 20.04, I had to uninstall virtualenv from the system: apt remove python3-virtualenv, and reinstall it using pip: pip install --user virtualenv --force-reinstall. I had errors about dependencies conflicts, I fixed them by calling pip install --user ${package} --force-reinstall for every package involved.
virtualenv is installed by default with python itself and when you install virtualenv via pip3 and try to create virtual environment using pipenv you will get this error:
ModuleNotFoundError: No module named 'virtualenv.seed.embed.via_app_data
check the version of installed virtualenv using apt list --installed
mine is:
python3-virtualenv/focal,focal,now 20.0.17-1 all [installed,automatic]
with the installed virtualenv by pip3
min is :
virtualenv 20.4.0
default installation of virtualenv is different with pip3 installed virtualenv
so when you try to create a virtual environment using pipenv for example installing django in a directory home/user/djano with pipenv install django~=3.1.5 you will get that error
the solution is remove installed virtualenv using pip3 uninstall virtualenv and use the default installation of virtualenv this time when you create virtual environment with pipenv it will create it successfully.
I want to have virtualenvwrapper. On Debian 10 testing I did:
apt remove python3-virtualenvwrapper # not purge, I want no changes in ~/.virtualenvs/
apt purge python3-virtualenv
/usr/bin/python3.8 -m pip install --force-reinstall virtualenvwrapper
/usr/bin/python3.8 -m pip install --force-reinstall virtualenv==20.0.23
.24 no longer works. I hope it will be solved sometimes...
EDIT 2021.01: I have changed my stack to: pyenv + pyenv-virtualenvwrapper + poetry. Ie. I use no apt or pip installation of virtualenv or virtualenvwrapper, and instead I install pyenv's plugin pyenv-virtualenvwrapper. This is easier way.
If someone encounters this problem inside existing env (when for example using pyenv) you can also use command below (found on GitHub when tried to fix poetry virtual env installation):
pip install --force-reinstall virtualenv
When I installed virtualenv via pip3, it failed to run virtualenv command. Then I changed the installation via:
sudo apt install python3-virtualenv
The virtualenv command can normally work.
I too had this issue. What I found is it is a permissions issue. For some unknown reason ownership of my home directory was off. I did a chown -R for the directory I was using for my project making myself the owner of my own directory and now everything works as normal.
I also had same issue, seems installed version has different user level so I followed their doc and below one work for me:
python3 -m virtualenv --help
To create new environment:
python3 -m virtualenv my_env
I also faced the same issue but after removing virtualenv which was installed with pip3, I could get rid of this error. Uninstall virtualenv with below command (don't forget to use sudo)
sudo pip3 uninstall virtualenv
After this, virtualenv command works totally fine.
It means that there are two virtualenv in your system.
One is "pip install" by sudo or root, the other may be installed by apt(if you are using ubuntu os)
Just uninstall one of them and the error should be fixed.
I fixed this error by removing all virtualenv and virtualenvwrapper related packages on system and reinstall the virtualenv and virtualenvwrapper with pip with below command(as i use ubuntu, so below only show apt)
remove all packages shown in below result
apt list --installed | grep virtualenvwrapper
apt list --installed | grep virtualenvwrapper
install virtualenv virtualenvwrapper with pip
pip install virtualenvwrapper virtualenvwrapper
set ~/.zshrc
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/amd
export VIRTUALENVWRAPPER_SCRIPT=/home/robot/.local/bin/virtualenvwrapper.sh
export VIRTUALENVWRAPPER_PYTHON=$(which python3)
source /home/robot/.local/bin/virtualenvwrapper.sh
When we use pip3 or python3 to install virtualenv then I got that error too. I had to run each time to create virtualenv (my_env is virtual environment name)
python3 -m virtualenv my_env
But if I install it using
sudo apt install virtualenv
Then virtualenv command works fine.
virtualenv my_env

Pipenv install on Ubuntu and WSL fails

For some reason when I run pipenv install it tries to execute my Windows python.exe:
OSError: [Errno 8] Exec format error: '/mnt/c/Users/<MY_USER_NAME>/AppData/Local/
Microsoft/WindowsApps/python.exe'
I am running WSL Ubuntu 18.04. I have installed Pipenv with the following commands:
sudo apt install python3-pip
pip3 install --user pipenv
python3 -m site --user-base
Added ~/.local/bin to ~/.profile PATH, and then source ~/.profile
This worked for me:
pipenv install --python=/usr/bin/python3.6
Explanation: https://github.com/pypa/pipenv/issues/3488
The python version on Windows is higher than that on WSL, making it
come before the latter one..
Specify python path explicitly can fix the problem:
$ pipenv --python /usr/bin/python3

Can't create a python virtual environment on Ubuntu 18.04

I'm a complete beginner to Ubuntu and I'm trying to create a virtual environment on Ubuntu 18.04. I had one running and it was working just fine, but I don't know what I did and know I cant get it to run.
I deleted my old env/ file and now I'm trying to create a new one using
python3 -m venv env
but I get the following error
Error: Command '['/home/user/app/env/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit s
tatus 1.
What gives?
Do you have the python3-venv package installed?
If not - install it with apt-get install python3-venv and try again python3 -m venv env
just reinstall your python3-venv
apt-get purge python3-venv
apt-get install python3-venv
and then create the virtualenv
python3.7 -m venv venvTest
if you have different version of python3, you should mention the exact python3 version.
you can also migrate your python3.6 to python3.7 by following guide migrate python3.6 to python3.7

"Cannot find installed version of python-django or python3-django" when running celery worker

When I run the command via ubuntu 15.04 terminal
celery worker -A celery_blog -l inf -c 5
I always get
Cannot find installed version of python-django or python3-django.
Though I have installed django for python 2.x as well as 3.x, you may refer the attached screenshot also.
Also, why even it's asking for django when running celery worker?
Solution 1:
pip install Django
Solution 2:
ubuntu version > 14.04. python3-django is a package available in the repos for Ubuntu 15.04. It isn't in the default repos for Ubuntu 14.04
apt-get install python3-django
There are a number of different ways in which you can install Django depending upon your needs and how you want to configure your development environment.
Global Install from Packages:
sudo apt-get update
sudo apt-get install python-django
You can test that the installation was successful by typing:
django-admin --version
Global Install through pip:
sudo apt-get update
Now you can install pip. If you plan on using Python version 2, install using the following commands:
sudo apt-get install python-pip
If, instead, you plan on using Python 3, use this command:
sudo apt-get install python3-pip
Now that you have pip, we can easily install Django. If you are using Python 2, you can type:
sudo pip install django
If you are using Python 3, use the pip3 command instead:
sudo pip3 install django
You can verify that the installation was successful by typing:
django-admin --version
Global Install through pip.

Categories