pipenv shell, does not activate the virtual environment - python

I'm trying to go to work with pipenv, but I have problems with the launch of the virtual environment.
errors:
➜ test_pipenv pipenv shell
Launching subshell in virtual environment…
. /home/user/.local/share/virtualenvs/test_pipenv-mzRyHdZF/bin/activate
➜ test_pipenv . /home/user/.local/share/virtualenvs/test_pipenv-mzRyHdZF/bin/activate
cd: **This is not a directory:** /home/user/.local/share/virtualenvs/test_pipenv-mzRyHdZF/bin/activate
or
➜ test_pipenv /home/user/.local/share/virtualenvs/venv-mzRyHdZF/bin/activate
zsh: **Access denied:** /home/user/.local/share/virtualenvs/venv-mzRyHdZF/bin/activate
or
➜ test_pipenv source /home/user/.local/share/virtualenvs/venv-mzRyHdZF/bin/activate
(test_pipenv) ➜ test_pipenv pip freeze
certifi==2018.10.15
chardet==3.0.4
idna==2.7
requests==2.19.1
urllib3==1.23
I installed the pipenv twice and get the same error:
sudo pip install pipenv
and
pip install --user pipenv
I get the same error
I use arch linux and zsh
.zshrc
export PATH=/usr/local/bin:$PATH
export SHELL=/bin/zsh
PIPENV_SHELL=/use/bin/zsh
export ZSH=/home/user/.oh-my-zsh
export PATH="$HOME/.local/bin:$PATH"
Help me please. Why does not it work pipenv shell?

Try doing this:
pip uninstall pipenv
this will uninstall existing pipenv
after doing that re-install pipenv by doing this:
pip install pipenv

check for permissions on your $HOME/.local/share/virtualenvs directory. If you are not allowed to create files/ directories in there, you cannot start a virtual env.

If you are In Arch Linux switch bash to fish.
Then run :
pipenv shell

(can't comment so I'll add this as an answer)
Hi,
From what I can tell you are doing all of this in terminal. If you do not have to work with pipenv, then I would recommend using virtualenv.
Install:
pip install virtualenv
Create a new virtual env:
virtualenv -p python3 your_env_name
load virtual env (from path where created file is located in):
source your_env_name/bin/activate
You can save your packages already installed with pip like this:
pip freeze > requirements.txt
and then load them in your virtual env (once you have loaded it) like this:
pip install -r requirements.txt
Hope this helps! :)

Related

How to import (install) dependencies (packages) from a global system environment to a virtual environment

I have installed my needed packages (dependencies) in the global system environment instead of my virtual environment (virtualenv) because i have used the command pip install <package-name> outside of the virtual environment.
So i want to know how can i make a list out of them and install them in any of my virtualenvs?
This is useful in a case that anyhow you have installed some packages (dependencies) in your global system environment instead of your virtualenv, by mistake.
For example by using the command "pip install", not "pipenv install" (outside of virtual environment).
So the solution is:
In the global system environment (outside of any virtualenv), create a "requirements.txt" file from all of your installed packages:
$ pip freeze > requirements.txt
Import installed dependencies from the created "requirements.txt" file to the Pipfile by running the below command in the root that the above created file "requirements.txt" exist; but first check:
a) If Pipfile not exist:
$ pipenv install
b) If Pipfile do exist (i.e. already created virtualenv):
$ pipenv install -r requirements.txt
Then your package listing files "Pipfile" & "Pipfile.lock" would be updated and locked.
But I personally recommend that for avoiding this problem to happen, always use the command
$ pipenv install
instead of $ pip install.
You can create file in your global system environment the format of this file is like following:
my_backages.txt
$ pip install -U Flask-SQLAlchemy
$ pip install --upgrade
$ pip install flask
then you can use pipfile as next :
$ pip install -r my_backages.txt

Is it possible to update Pipfile after installing packages using pip install?

I just created a pipenv environment using pipenv --python 3.9. I then did pipenv shell and started installing packages with pip install. It turns out this doesn't seem to be the usual way of doing things with pipenv. Is there any command I can run to update the Pipfile with all the packages I installed with pip install? I searched but couldn't find anything.
When you have multiple packages you'd like to install, you usually have whats called a requirements.txt file, that contains all the packages you'd like to use for your project.
You can run
$ pipenv run pip freeze > requirements.txt
To generate the requirements file to the current directory you're in, while the virtual environment is active.
Initially you're going to have to install all your packages manually. But after you can run
$ pipenv install -r path/to/requirements.txt
to import all the packages in requirements.txt from the shell/virtual environment.
Instead of running pipenv shell and then pip install <package>, you should simply run pipenv install <package> (outside the virtual environment, from the same location you ran pipenv --python 3.9).
This will install the package in your virtual environment and will automatically update your Pipefile and Pipfile.lock files.
You may skip the Pipfile.lock update by using --skip-lock flag - pipenv install --skip-lock <package>
You can use pipreqs which generates requirements.txt file based on imports.
pip install pipreqs
pipreqs
pipenv install -r requirements.txt

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 pip can't install packages

I'm having trouble installing packages using virtualenv with python. I do the following:
sudo virtualenv venv
cd venv/bin
source activate
pip install nose
I get the following error:
unable to execute /Users/../venv/bin/pip: No such file or directory
What am I doing wrong here?
run:
cd /usr/local/bin
sudo ./pip install virtualenv
which virtualenv
This should point to /usr/local/bin/virtualenv
which pip
This should point to /usr/local/bin/pip
virtualenv /Users/yourname/path/to/env/envname

How to freeze packages installed only in the virtual environment?

How to freeze packages installed only in the virtual environment, that is, without the global ones?
You need to use the -l or --local option to freeze only the local packages (and not the global ones)
pip freeze -l > requirements.txt
Make sure you are working in the virtualenv before doing pip freeze -l.
Only local packages on virtual environment
pip freeze -l > requirements.txt # or --local instead of -l
Only local packages installed by the user on virtual environment
pip freeze --user > requirements.txt
See the documentation for further details: https://pip.pypa.io/en/stable/reference/pip_freeze/.
For me (macOS) the following worked
path/to/venv/bin/pip3 freeze -l
I'm on Windows 10, python 3.6, with my virtual environment called env activated using command prompt I found that pip freeze -l does not work (error), python -m pip freeze -l does not work (gets global packages) but changing into my virtual environment Scripts directory and running pip freeze or pip freeze -l works. Here is an example of this solution/work-around with my virtual environment, env:
cd \env\Scripts
pip freeze > ..\..\requirements.txt
python venv/Path_to/bin/pip freeze -l
I did try everything, even i inside venv it not worked. This code worked for me. It shows only pip packages in venv.
venv\Scripts\python.exe venv\Scripts\pip.exe freeze > requirements.txt
Install whatever you need to freeze in your virtual environment, and then
pip freeze > requirements.txt
After that install the packages in the virtual environment that you do not want to freeze.
Try the following command:
pip -E /path/to/env/ freeze

Categories