Not able to create an virtual environment using pipenv - python

I'm trying to create an virtual environment with Python 3.7, using the pipenv command. Trying to run pipenv install --python=python3.7 gives the error below:
pipenv install --python=python3.7
loading virtual environment veriables
Creating a virtual environment for this project
Using path/to/python3.7 (3.7.0) to create virtualenv...
Creating virtual environment... Already using interpreter path/to/python3.7
New python executable in /home/user/.local/share/myproject/bin/python3.7
Not overwriting existing python script /home/user/.local/share/myproject/bin/python (you must use /home/user/.local/share/myproject/bin/python3.7)
failed to create a virtual environment.
How can I create a virtual environment using pipenv?

There are several ways to create a virtual environment, try with these commands
sudo pip3 install virtualenv
# After this installation
python -m virtualenv vnvname
or
python3 -m virtualenv vnvname
It will create a virtual environment

You can use the virtualenv command
virtualenv -p python3 envname
Update :
pip install --upgrade virtualenv

I had this error in PyCharm using Kubuntu (Linux)
Failed to create virtual environment
Found the answer in here Create a Python3 virtual environment to just run this command
sudo apt-get -y install python3-dev python3-pip libkrb5-dev

Related

How to install ipykernel just for current project?

I want to install a package which is just used in one project.
So I create a virtual env and install it
python -m venv .venv --system-site-packages
python -m pip install my_package
Then I want to debug it with jupyter.
The problem is It seems I have to either install another jupyter in my virtual env ( quite large):
pip install jupyter
jupyter notebook
or register this env as a kernel to user:
python -m ipykernel install --user --name my_test_env
in this case, this env will list in my global kernel list but I won't use if for any other project. And delete the project folder will leave a broken kernel in global jupyter.
Is there any way to register a kernel just for current project?

How do I install virtualenv in Python 3.10.2 and activate it for a telegram bot?

I tried some guides that I found but nothing works. I need this virtual env for a telegram bot. I| use Visual studio code
How to install virtualenv:
Install pip first
sudo apt-get install python3-pip
Then install virtualenv using pip3
sudo pip3 install virtualenv
Now create a virtual environment
virtualenv venv
you can use any name insted of venv
You can also use a Python interpreter of your choice
virtualenv -p /usr/bin/python2.7 venv
Active your virtual environment:
source venv/bin/activate
Using fish shell:
source venv/bin/activate.fish
To deactivate:
deactivate
Create virtualenv using Python3
virtualenv -p python3 myenv
Instead of using virtualenv you can use this command in Python3
python3 -m venv myenv
Its looks like your problem is activating the virtual environment.
source env/bin/activate
or just type activate in your terminal.
If you are using windows try:-
env\Scripts\activate.bat
Install. To create a virtual environment, use the following command, where .venv is the name of the environment folder:
python -m venv .venv
Activate. When you create a new virtual environment, a prompt will be displayed to allow you to select it for the workspace.
This will add the path to the Python interpreter from the new virtual environment to your workspace settings. That environment will then be used when installing packages and running code through the Python extension.
You can switch environments at any time at the bottom left corner of VS Code window or using the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P).

Why do my dependencies that I've installed in my virtual environment appear outside as well using pip

I've installed dependencies using python3 -m pip... in my virtual environment which I created with and activated by python3 -m venv env && source env/bin/activate, I've even checked if it was activated by echo $VIRTUAL_ENV which gave me .../env however when I do python3 -m pip list in my virtual environment and outside I get the same results. Why do my dependencies in my virtual environment show up outside?

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

virtualenv edits system-wide settings

I installed a new virtual environment using the following command:
sudo virtualenv --python=python3.4 mysite
Then, I edited the permissions of the newly created folder:
sudo chmod -R 777 mysite/
I then proceeded to activate the virtual environment:
source mysite/bin/activate
The virtualenv was activated with (mysite) showing up before the prompt.
On my system-wide python packages I have django version 1.7.1 installed. I wanted to install django 1.8 to the virtualenv. So, I did this:
sudo pip3 install django==1.8
But to my horror, it deleted django 1.7.1 from my system and installed 1.8 on the system, not just the virtualenv as I wanted.
I confirmed this by running:
python -c "import django; print(django.get_version())"
It returns 1.8 both when the virtualenv is activated as well as deactivated.
How do I install 1.8 only inside the virtualenv, without affecting the system-wide django version?
No need to use sudo virtualenv Use only virtualenv
Purpose of virtualenv is to get isolated python environment.
When you are inside virtualenv don't use sudo pip / sudo pip3.
Use pip without sudo. sudo pip is used to install python packages system wide.
So, normal workflow is
virtualenv --python=python3.4 mysite
source mysite/bin/activate
pip install <package_name_version> like pip install django==1.8
My guess is that the environment variables that specify the python / pip to use (especially PATH) are not passed through sudo. Why do you have to sudo anything anyway? Just create the virtualenv as your user, source bin/activate as your user, and run pip as your user.
For more information: man sudoers and search for Command environment.
dont use sudo while installing djando via pip and also try to use sudo less for creating virtual env and for changing permissions.
i have tried these way and have done it

Categories