I can't do anything with pipenv - python

ERROR:: --system is intended to be used for pre-existing Pipfile installation, not installation of specific packages. Aborting.
I can't use pipenv in Ubuntu18.04.
How can I fix it?

This is an open issue in the Pipenv repository: https://github.com/pypa/pipenv/issues/5052.
From the discussion in the thread, it seems to pop up when there is an existing virtualenv that was created with the same directory path. The solution mentioned in the thread is to simply remove this virtualenv which fixes the issue.

You can use the python virtual environment,
python -m venv venv # Creates virtual environment
To activate virtual environment do source venv/bin/activate
Then you can install your packages using pip install lib
To deactivate virtual environment type deactivate

Related

Pip installs packages in pyenv root even when virtual environment is activated

I try to install a package with pip in a virtual environement previously created with venv. The Python version is managed through pyenv. I don't want to use pyenv to create the virtual environment.
The project is set up this way. To the project empty directory, I added a .python-version containing the version 3.8.2. Then I created my virtual environement using python -m venv .venv. Then I activated the environement using source .venv/bin/activate. Now the command line starts with a (.env). However, when I try to install some package with pip install some-package, the package ends up in {pyen_home}/versions/3.8.2/lib/python3.8/site-packages, instead of the virtual environment.
What's irritating is that I'm almost certain that I did manage to install package in the virtual environment that way before, but not anymore, so I don't see what I'm missing.
Content of your .python-version should be .venv.
As far as I know you should not create this file by yourself. It generated when you run pyenv local .venv. And venv activates automatically.
Also proper way to create virtual environment is pyenv virtualenv {python-version} {venv-name}. Read the docs carefully.

How do I activate python virtual environment from a different repo?

So am working in a group project, we are using python and of the code is on GitHub. My question is how do I activate the virtual environment? Do I make one on my own using the "python virtual -m venv env" or the one that's on the repo, if there is such a thing. Thanks
virtual env is used to make your original env clean. you can pip install virtualenv and then create a virtual env like virtualenv /path/to/folder then use source /path/to/folder/bin/activate to activate the env. then you can do pip install -r requirements.txt to install dependencies into the env. then everything will be installed into /path/to/folder/lib
alteratively, you can use /path/to/folder/bin/pip install or /path/to/folder/bin/python without activating the env.
Yes, you'll want to create your own with something like: python -m venv venv. The final argument specifies where your environment will live; you could put it anywhere you like. I often have a venv folder in Python projects, and just .gitignore it.
After you have the environment, you can activate it. On Linux: source venv/bin/activate. Once activated, any packages you install will go into it; you can run pip install -r requirements.txt for instance.

install packages in Python2 with Python3

I am trying to install numpy, nltk, etc packages for Python 2 to run a code. But I have Python3 as well and the path variable is set to it. When I try to use any pip install command it shows the package is available in Python3's directory.
Also, I am using VSCode, so I did not add the path variable.
I suggest you use virtual environments. Because if you read about virtual environments, you will find that they are created for such cases.
To create virtual environments, you must do the following:
Make a note of the full file path to the custom version of Python you just installed.
virtualenv -p /home/username/opt/python-2.7.15/bin/python venv
In order to use this environment’s packages/resources in isolation, you need to “activate” it. To do this, just run the following:
source venv/bin/activate (Linux)
./venv/Scripts/activate.bat (Windows)
Notice how your prompt is now prefixed with the name of your environment (venv, in our case). This is the indicator that venv is currently active, which means the python executable will only use this environment’s packages and settings.
Now run the following:
(venv) $ which python
/Users/ashkan/python-virtual-environments/venv/bin/python (in my case)
now you have access to python2.7.
The best practice for this particular problem would be virtual environments.And for that matter Pipenv would be a good option.
Install Pipenv.
$ brew install pipenv (MacOs)
$ sudo apt install pipenv (Debian)
$ sudo dnf install pipenv (Fedora)
pip install pipenv (Windows)
Creating virtual env with Pipenv.
pipenv install --python 2.7 numpy
This command will install create a virtual environment and install python 2.7(which will be used as the main interpreter once you activate the environment) along with numpy in that environment. This will avoid the packages version conflicts too.
To activate the environment
pipenv shell
If you are working in the Vs Code workspace then you should set the interpreter path(python path) to the path of the virtual environment.
when we install anything using pip. it will install dependencies for default python version. so you can change the default python version using this link https://linuxconfig.org/how-to-change-from-default-to-alternative-python-version-on-debian-linux
Hope this will solve your problem
After crating a virtual environment with python 2.7 you can install your required packages

What is the process to clone a repo and recreate the python virtual enviroment using the pipenv.lock file?

What is the process to clone a repo and recreate the python virtual environment using the pipenv.lock file?
On my development system, I created a virtual environment using pyenv and pipenv , and am ready to test my code on another system. I've installed pyenv/pipenv/python(same version as dev machine) on the test system, but I don't how to tell pipenv to create an identical virtual environment on the test system using the content of the version-controller Pipfile.lock file.
do I do 'pipenv install --python '?
or just 'pipenv install' and it will find and read the .lock file?
pipenv install --python <version>
pipenv install
I expect a virtual environment with all of the requirements/dependencies specified in the lock file to be installed.
According to this article it's just:
pipenv install --ignore-pipfile
This tells Pipenv to ignore the Pipfile for installation and use what’s in the Pipfile.lock. Given this Pipfile.lock, Pipenv will create the exact same environment you had when you ran pipenv lock, sub-dependencies and all.

Virtualenv says "root" instead of the name of virtualenv?

For a while, I have been using virtualenv's for many python projects. When I tried to activate one of my virtualenv's, I typed:
source venv/bin/activate
Which generally does the trick. However, instead of my command prompt saying:
(venv)me#example:~/
It says:
(root)me#example:~/
My python version requirement and my packages that I installed on the virtualenv are not recognized. Why does this happen?
Try:
source activate venv
(instead of source venv/bin/activate or ./venv/bin/activate.sh etc.)
THundtMac$ source activate venv
(venv) THundtMac$ source deactivate
THundtMac$ . ./venv/bin/activate
(root) THundtMac$ source deactivate
THundtMac$
I think this has to do with using Anaconda vs the pip-installed version. (I'm using the conda-installed one now.)
Once in the virtual environment bin folder, typing:
source ./activate
instead of:
source activate
solved the problem for me.
Please note that the latter command actually activate a "base" environment (called "root" if you use the pip version of virtualenv, and "base" if you use the conda version of virtualenv), and not the environment you are actually trying to activate

Categories