ModuleNotFoundError: No module named 'virtualenv.seed.via_app_data - python

I had installed virtualenv by sudo -H pip3 install virtualenv, and created a venv by virtualenv, but now I can't create env in my new Django project that includes Pipfile.
I tried:
$ pipenv shell
But its result is:
Creating a virtualenv for this project...
Pipfile: /home/mostafa/py38/lib/python3.8/site-packages/carfix/Pipfile
Using /usr/bin/python3.8 (3.8.5) to create virtualenv...
⠹ Creating virtual environment...ModuleNotFoundError: No module named 'virtualenv.seed.via_app_data'
✘ Failed creating virtual environment
I tried these answers but the problem is not yet resolved:
Answer 1

I finally found the solution to the problem:
I Used poetry lockfor one app and everything worked fine!
I Used poetry lock for a second app and received the following error message:
$ poetry lock
Creating virtualenv mytestapp-vm7OCEgV-py3.8 in /home/alexb7217/.cache/pypoetry/virtualenvs
ModuleNotFoundError
No module named 'virtualenv.seed.via_app_data'
at <frozen importlib._bootstrap>:973 in _find_and_load_unlocked
Followed the most simple suggestion:
$ sudo apt remove --purge python3-virtualenv
Re-ran poetry-lock
$ poetry lock
Updating dependenciesResolving dependencies... (1.1s)
Everything works great, that's it! ;)

The solution is to remove the installed virtualenv using
pip3 uninstall virtualenv
And use the default installation of virtualenv then :
pipenv shell

Try to remove your virtualenv installation and try to install it via:
sudo apt-get install virtualenv.
Then create virtualenv with:
virtualenv virtualenv_dir
Where virtualenv_dir is your Django project folder

I had the same issue. I was not able to select an existing environment nor create one.
What I did was to create one from the terminal:
virtualenv venv
get into it
. venv/bin/activate
install the requirements I had, with pip3 no pip:
pip3 install -r requirements.txt
and when I went back to pycharm, it asked me if I wanted to use that environment I just created.

Related

I used pip3 to install virtualenv but I can't create venv and also I can't uninstall virtualenv

I'm using Linux Mint 20.2 with two directories / and /home.
I used the following command to install virtualenv:
>>> sudo pip3 install virtualenv
It worked fine and it installed in the following path:
>>> virtualenv --version
virtualenv 20.0.17 from /usr/lib/python3/dist-packages/virtualenv/__init__.py
But when I tried to create an environment I got the following error:
>>> python3 -m venv article
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 install python3.8-venv
You may need to use sudo with that command. After installing the python3-venv
package, recreate your virtual environment.
Failing command: ['/home/username/article_tools/article/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']
When I tried to uninstall it to install it using [b]sudo apt install python3.8-venv[/b], I got the following error:
>>> sudo pip3 uninstall virtualenv
Found existing installation: virtualenv 20.0.17
Not uninstalling virtualenv at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'virtualenv'. No files were found to uninstall.
How can I fix it? By fix, I mean installing virtualenv in a way that I don't get such errors.
The fundamental problem here seems to be that you are mixing up two different packages.
Python 3 comes with a built-in virtual environment module venv which is however not installed by default on Debian-based platforms. Like the error message says, apt-get install -y python3-venv will install this package, which you can then use with python3 -m venv.
virtualenv is a separate third-party package which you invoke with the command virtualenv. It's not a bad alternative, but if you are only just learning, I would suggest you simply ignore it for the time being.

Creating a virtual environment returns No such file or directory

When I try python3 -m venv venv, terminal returns
python3: posix_spawn: /Library/Frameworks/Python.framework/Versions/3.8/bin/python3.82.7:No such file or directory
I have seen other posts mentioning Home Brew related issues but I doubt this is the case. I did try uninstalling and installing Python.
Note: I was connected to localhost with a virtualenv. When I tried again later on, this was returned. I am building a Flask application.
Now you can use pipenv library for creating the virtual environment.
pipenv install pipenv
for example:
mkdir testapp
cd testapp
pipenv shell
Now the virtual environment is ready.
Then to install libraries in the virtual environment instead of "pip" you have to use "pipenv".
For example:
pipenv install requests
pipenv install flask
Then to write the requirements.txt you can use
pip freeze > requirements.txt
To uninstall libraries:
pipenv uninstall requests
Each time to work on the virtual environment:
pipenv shell
How to exit the virtual environment?
exit

Install pipenv and project dependencies using a makefile

I want to create a make file using which I can automate the virtual environment creation and installation of project dependencies. I've create the following rule:
setup-env:
sudo apt-get install python3 pip
pip install pipenv
pipenv shell
pipenv install
I am able to install python, pipenv and create a virtual environment.
But the last line pipenv install is not getting execute because the control shifts to virtual environment. When I exit from the virtual environment, the install command gets executed.
Is there a way to install dependencies without creating a separate rule?
Thanks!
You can simple install before going into the shell
(pipenv can be installed outside the shell)
change the order of your rules:
setup-env:
sudo apt-get install python3 pip
pip install pipenv
pipenv install
pipenv shell

Pip not working inside Virtual Env but works outside perfectly

Hello Guys I am tying to follow the installation here https://github.com/systers/portal and trying to deploy the server inside a virtual environment on my machine.
After lots of errors I decided to install a fresh copy of Ubuntu 16.04 and start
After the installation here are the things that I have installed using the given commands
I checked my current python and python3 versions using python --version and python3--version respectively and they are Python 2.7.12 and Python 3.5.2 respectively.
Easy Install. $ sudo apt-get install python-setuptools python-dev build-essential
pip. $ sudo easy_install pip
virtualenv. $ sudo pip install --upgrade virtualenv.
python3-dev tools.$sudo apt-get install python3-dev
Now after that I created a virtual env and activated it using the following commands
$ virtualenv venv1 --python=/usr/bin/python3
$ source venv/bin/activate
But now when I run the third command
$ pip install -r requirements/dev.txt
or even do
$pip --version
I get the error
bash: /media/rohan/New Volume/portal/venv1/bin/pip: "/media/rohan/New: bad interpreter: No such file or directory
Also in /venv1/bin the files pip,pip3 ,pip3.5 are present
I tried sudo easy_install pip thinking that it will install pip in the virtual environment but it installs to /usr/local/bin
Also I tried by creating a virtual env using the code
$virtualenv venv --python=/usr/bin/python
But that also doesnt work and this time also same error comes and in /venv/bin pip pip2 pip2.7 are present
PLEASE HELP
The problem appears to be that the path to your virtualenv has a space in it that isn't being escaped somewhere it should be.
Note the error you receive:
/media/rohan/New: bad interpreter: No such file or directory
So with that space in the path, it is trying to run a program that doesn't exist (/media/rohan/New) on a file that doesn't exist (Volume/portal/venv1/bin/pip).
Renaming New Volume to something without spaces like new_volume and then recreating a virtualenv should resolve this.
I had renamed the folder of virtual environment so that I was getting this error.
Then I renamed the venv folder name to the path mentioned in the error (That is the one which I had named while creating venv.) then tried to use pip and it worked.
Might be you have already solved your issue, but this is for the future visitors.

pip freeze does not show all installed packages

I am using a virtualenv. I have fabric installed, with pip. But a pip freeze does not give any hint about that. The package is there, in my virtualenv, but pip is silent about it. Why could that be? Any way to debug this?
I just tried this myself:
create a virtualenv in to the "env" directory:
$virtualenv2.7 --distribute env
New python executable in env/bin/python
Installing distribute....done.
Installing pip................done.
next, activate the virtual environment:
$source env/bin/activate
the prompt changed. now install fabric:
(env)$pip install fabric
Downloading/unpacking fabric
Downloading Fabric-1.6.1.tar.gz (216Kb): 216Kb downloaded
Running setup.py egg_info for package fabric
...
Successfully installed fabric paramiko pycrypto
Cleaning up...
And pip freeze shows the correct result:
(env)$pip freeze
Fabric==1.6.1
distribute==0.6.27
paramiko==1.10.1
pycrypto==2.6
wsgiref==0.1.2
Maybe you forgot to activate the virtual environment? On a *nix console type which pip to find out.
You can try using the --all flag, like this:
pip freeze --all > requirements.txt
Although your problem was specifically due to a typo, to help other users:
pip freeze doesn't show the dependencies that pip depends on. If you want to obtain all packages you can use pip freeze --all or pip list.
If you have redirected all the pre-installed packages in a file named pip-requirements.txt then it is pretty simple to fix the above issue.
1) Delete your virtualenv folder or create new one (I am giving it a name as venv)
rm -rf venv && virtualenv venv
2) Install all the requirements/dependencies from the pip-requirements.txt
pip install -r pip-requirements.txt
3) Now you can check the installed packages for your Django application
pip freeze
4) If you had forgotten to update your requirements file(pip-requirements.txt), then install fabric again (Optional Step)
Note: After installing any dependency for your Django app, always update the requirements in any file as follows (make sure your virtualenv is activated)
pip freeze > pip requirements.txt
That's it.
Adding my fix in addition of above fix also ,
I was also facing the same issue on windows,even after activating the virtualenv too pip freeze was not giving me all list of installed packages. So i upgraded my pip with python -m pip install --upgrade pip command and then used pip freeze.
This time it worked and gave me all list of installed packages.
This might be stupid but I have got the same problem. I solved it by refreshing vs code file directory (inside vscode there is a reload button). :)
If none of the above answers are working for you.
As with me you might have problem in you venv and pip configuration.
Go inside your venv/bin and open pip and see the 2nd line as:
'''exec' "path/to/yourvenv/bin/python3" "$0" "$#"
See if this line is correctly pointing inside your venv or not
For example in my case.
I initially named my virtual environment as venv1
and later just renamed it to venv2.
In doing so my pip file 2nd line had: '''exec' "venv1/bin/python3" "$0" "$#"
which to work properly should have: '''exec' "venv2/bin/python3" "$0" "$#" notice "venv2" not "venv1" since venv1 in now renamed to venv2.
Due to this python was looking inside pip of venv2 and throwing error or not working as desired.
For those who added Python modules via PyCharm IDE, after generating a virtual environment from the command prompt, good luck! You will need to rebuild the requirements.txt file manually with the ones missing by first running pip3 freeze and adding what is missing from PyCharm.
I highly suggest switching to Visual Studio Code.

Categories

Resources