pipenv icon indicating copy to clipboard operation
pipenv copied to clipboard

`pipenv install` throws `--system is intended to be used for pre-existing Pipfile installation`

Open ajeetdsouza opened this issue 3 years ago • 32 comments

Issue description

Running pipenv install in a new project throws an error, if there was a project created before with the same directory path.

Expected result

pipenv should be able to handle this situation without error. Not sure what the best approach would be here.

Steps to replicate

  1. Create a pipenv project:
$ mkdir foo
$ cd foo
$ pipenv install
  1. Delete the pipenv project:
$ cd ..
$ rm -rf foo
  1. Create a new project again:
$ mkdir foo
$ pipenv install
  1. You get an error:
Usage: pipenv install [OPTIONS] [PACKAGES]...

ERROR:: --system is intended to be used for pre-existing Pipfile installation, not installation of specific packages. Aborting.
$ pipenv --support

Pipenv version: '2022.4.8'

Pipenv location: '/opt/homebrew/Cellar/pipenv/2022.4.8/libexec/lib/python3.10/site-packages/pipenv'

Python location: '/opt/homebrew/Cellar/pipenv/2022.4.8/libexec/bin/python3.10'

Python installations found:

  • 3.9.12: /opt/homebrew/bin/python3
  • 3.9.12: /opt/homebrew/bin/python3.9
  • 3.8.9: /usr/bin/python3

PEP 508 Information:

{'implementation_name': 'cpython',
 'implementation_version': '3.10.2',
 'os_name': 'posix',
 'platform_machine': 'arm64',
 'platform_python_implementation': 'CPython',
 'platform_release': '21.4.0',
 'platform_system': 'Darwin',
 'platform_version': 'Darwin Kernel Version 21.4.0: Fri Mar 18 00:47:26 PDT '
                     '2022; root:xnu-8020.101.4~15/RELEASE_ARM64_T8101',
 'python_full_version': '3.10.2',
 'python_version': '3.10',
 'sys_platform': 'darwin'}

System environment variables:

  • PATH
  • MANPATH
  • NIX_PROFILES
  • TERM_PROGRAM
  • _P9K_TTY
  • SHELL
  • TERM
  • HOMEBREW_REPOSITORY
  • TMPDIR
  • PYPI_SERVER_PASSWORD
  • TERM_PROGRAM_VERSION
  • PIPENV_SYSTEM
  • TERM_SESSION_ID
  • USER
  • SSH_AUTH_SOCK
  • _
  • __CFBundleIdentifier
  • PWD
  • JAVA_HOME
  • P9K_SSH
  • BASE16_THEME
  • P9K_TTY
  • XPC_FLAGS
  • NIX_SSL_CERT_FILE
  • XPC_SERVICE_NAME
  • PYPI_SERVER_USER
  • SHLVL
  • HOME
  • HOMEBREW_PREFIX
  • LOGNAME
  • LC_CTYPE
  • INFOPATH
  • HOMEBREW_CELLAR
  • __CF_USER_TEXT_ENCODING
  • PIP_SHIMS_BASE_MODULE
  • PIP_DISABLE_PIP_VERSION_CHECK
  • PIP_PYTHON_PATH
  • PYTHONDONTWRITEBYTECODE
  • PYTHONFINDER_IGNORE_UNSUPPORTED

Pipenv–specific environment variables:

  • PIPENV_SYSTEM: 0

Debug–specific environment variables:

  • PATH: /opt/homebrew/Cellar/pipenv/2022.4.8/libexec/tools:/Users/ajeet.dsouza/.deno/bin:/Users/ajeet.dsouza/.local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/ajeet.dsouza/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/ajeet.dsouza/.cargo/bin:/Users/ajeet.dsouza/.local/bin
  • SHELL: /bin/zsh
  • PWD: /Users/ajeet.dsouza/ws/bot-detection

ajeetdsouza avatar Apr 17 '22 21:04 ajeetdsouza

I can vouch for this issue as well.

ThijmenGThN avatar Apr 18 '22 22:04 ThijmenGThN

I also get this issue. I avoid this by editing Pipfile directly.

lazmond3 avatar Apr 19 '22 04:04 lazmond3

.

Alireza-RST avatar Apr 19 '22 08:04 Alireza-RST

I solve this by removing the previous virtualenv.

Alireza-RST avatar Apr 19 '22 08:04 Alireza-RST

I can replicate as well. Removing existing environment works.

DrPyser avatar Apr 19 '22 22:04 DrPyser

I have a fair amount on my plate right now and won't be getting to this immediately -- anyone on this thread want to investigate a potential fix?

matteius avatar Apr 20 '22 02:04 matteius

pipenv-2022.1.8 works, pipenv-2022.3.23 bails with this error on my mac.

abrahm avatar Apr 22 '22 04:04 abrahm

Also getting this issue with pipenv-2022.4.20 on Windows 10.

amber-ailuridae avatar Apr 22 '22 18:04 amber-ailuridae

There exists another folder having same name of the deleted folder in the beginning, under '.virtualenvs' folder.

pipenv --venv

This command will find the path of that folder. Then deleting that folder fixed the issue.

MdShihabAhmed avatar Apr 25 '22 18:04 MdShihabAhmed

I've solved this issue by removing previous virtualenv like following:

My environment

CentOS Linux release 7.9.2009 (Core)
pipenv Version: 2022.4.8
pip Version: 21.3.1

This is our issue

cd dir_python
pipenv --python 3
> Usage: pipenv [OPTIONS] COMMAND [ARGS]...
> ERROR:: --system is intended to be used for pre-existing Pipfile installation, not installation of specific packages. Aborting.

This is my solution : Remove existing virtualenv

# Check where virtual venv is
pipenv --venv
> /home/0816keisuke/.local/share/virtualenvs/dir_python-5Rka8dPB

# Remove existing virtualenv
cd ~/.local/share/virtualenvs
rm -rf dir_python-5Rka8dPB

# Remake virtualenv
cd ~/dir_python
pipenv --python 3

It's the almost same as MacOS.

Hope this helps you!!

0816keisuke avatar Apr 26 '22 05:04 0816keisuke

Solved

ERROR:: --system is intended to be used for pre-existing Pipfile installation, not installation of specific packages. Aborting.

If you are using macOS, I deleted the project file in my virtualenv folder

  1. Using GO I went to this folder -> ".local/share/virtualenvs/"
  2. Take note of your project folder name, if your project folder is "myProject", in the virtualenv folder, you will see your project name with alphanumeric appended at its end, I simply moved to Bin
  3. created a new project with "pipenv install" and the error was gone

Virtualenv location: /Users/your-computer-name/.local/share/virtualenvs/myProject-0dhhge

Hope this helps

Iotechpod avatar May 01 '22 20:05 Iotechpod

I encounter this same issue inside a docker build process. The suggested fix does not apply because there is no pre-existing venv in my case. The image builder starts from scratch obviously.

The pipenv version used is version 2022.4.30. Executing pipenv --venv right before pipenv install --system confirms that no venv exists yet:

No virtualenv has been created for this project(/app) yet!

Installing pipenv==2022.1.8 doesn't help either.


EDIT: I looked into pipenv's code to find out why it does not work. I found that the code checks for Pipfile.lock file existence. Indeed, when I add the Pipfile.lock into the build process, it works. Not sure if this behavior is intentional. I think in this case the error message should be improved, because it does not mention the missing Pipfile.lock at all.

rsnitsch avatar May 02 '22 12:05 rsnitsch

There exists another folder having same name of the deleted folder in the beginning, under '.virtualenvs' folder.

pipenv --venv

This command will find the path of that folder. Then deleting that folder fixed the issue.

This worked for me. Thanks

jaypnchl avatar May 04 '22 06:05 jaypnchl

There exists another folder having same name of the deleted folder in the beginning, under '.virtualenvs' folder.

pipenv --venv

This command will find the path of that folder. Then deleting that folder fixed the issue.

This can be done in one line. rm -rf "$(pipenv --venv)" on UNIX systems.

PythonCoderAS avatar May 21 '22 00:05 PythonCoderAS

Improved solution:

pipenv --rm

Would be nice if code caught this error and suggested that command as an option.

gregglind avatar May 30 '22 15:05 gregglind

Maybe the source:

https://github.com/pypa/pipenv/blob/114eb8f80a63e519fe9d12ac9e7cb60444cf47c0/pipenv/core.py#L251-L258

gregglind avatar May 30 '22 16:05 gregglind

Yeah, I could use some help with some of these long standing issues to be honest. For context, the weather here is amazing and gardening season is happening, so my time will be limited to mostly reviewing other's efforts and making suggestions and new releases until the Fall/Winter cycle again. With regards to this system issue, I don't even understand the concept that --system is intended to be used for pre-existing Pipfile installation, not installation of specific packages. Aborting. -- My question is why the heck can pipenv not be used to install system level packages when pip does this by default?

I don't think that removing a local virtualenv is the desired solution, it is more of a workaround. I think the --system flag should be able to install things at a system level when it is supplied, and presumably there is a Pipfile config option for specifying to always install to the system level. This would better support the ability to do what people want to do, and for whatever the reason -- maybe it is they are running a Docker container that just uses the root user, though I tend to agree its better to have an actual user -- either way, some folks may not want the overhead of using virtualenv in their docker containers for whatever reason. Am I making any sense? Going back outside before it gets too hot.

matteius avatar May 30 '22 16:05 matteius

@matteius I fully agree.

In one of my projects I used this workaround in the Dockerfile:

# Copy only the Pipfile.
COPY Pipfile ./

# Generate the Pipfile.lock during the image build process, then immediately remove the venv.
RUN pipenv lock && pipenv --clear && pipenv --rm

# Now install from Pipfile.lock into system packages...
RUN pipenv install --system --deploy

Ugly but it does the job.

rsnitsch avatar May 31 '22 08:05 rsnitsch

try this

pipenv --rm

lucasmgana avatar Jun 03 '22 07:06 lucasmgana

@ajeetdsouza and @rsnitsch -- I am prototyping a branch that removes this check -- please have a look and help consider what other implications exist. I'll have to look at test failures later on when I get more time; I haven't run the test suite yet, but it seems to work about how I'd expect.

matteius avatar Jun 24 '22 10:06 matteius

There exists another folder having same name of the deleted folder in the beginning, under '.virtualenvs' folder.

pipenv --venv

This command will find the path of that folder. Then deleting that folder fixed the issue.

This helped me too!

VaibhavSingh8 avatar Jul 05 '22 05:07 VaibhavSingh8

I solve this by removing the previous virtualenv.

Please, add a error msg if pipenv finds a folder in .virtualenvs with the same name of the folder which intends to create

AucaCoyan avatar Jul 12 '22 12:07 AucaCoyan

I solve this by removing the previous virtualenv.

Please, add a error msg if pipenv finds a folder in .virtualenvs with the same name of the folder which intends to create

I agree, the error message is cryptic and not even related to the actual issue. I am not using --system, and while #5144 does address usage of --system, I would like to know why Pipenv thinks I am using --system. Is that the default when the venv directory exists but a Pipfile does not?

PythonCoderAS avatar Jul 12 '22 12:07 PythonCoderAS

@matteius I fully agree.

In one of my projects I used this workaround in the Dockerfile:

# Copy only the Pipfile.
COPY Pipfile ./

# Generate the Pipfile.lock during the image build process, then immediately remove the venv.
RUN pipenv lock && pipenv --clear && pipenv --rm

# Now install from Pipfile.lock into system packages...
RUN pipenv install --system --deploy

Ugly but it does the job.

This worked for me!

olahsymbo100 avatar Aug 02 '22 10:08 olahsymbo100

If you go to C:\Users_username_.virtualenvs and delete the folder inside, you can start another virtual environment in the same folder. You will just have to install all the modules again

Kevin-Robbs avatar Aug 28 '22 16:08 Kevin-Robbs

That is equivalent to pipenv --rm.

PythonCoderAS avatar Aug 29 '22 00:08 PythonCoderAS

The same thing happened to me in Windows 10. The problem was that the "Windows Defender" antivirus blocked access to folders or files to not allow modifications by hostile applications. The function is called "Controlled Access to Folders" and it has to be disabled otherwise the virtual environment cannot be created correctly. Once disabled, you should check if you have a virtual environment with the following command: pipenv --venv

If you have a virtual environment you have to delete it. pipenv --rm

Then you must recreate your virtual environment. pipenv shell

MFES07 avatar Aug 30 '22 19:08 MFES07

I've solved this issue by removing previous virtualenv like following:

My environment

CentOS Linux release 7.9.2009 (Core)
pipenv Version: 2022.4.8
pip Version: 21.3.1

This is our issue

cd dir_python
pipenv --python 3
> Usage: pipenv [OPTIONS] COMMAND [ARGS]...
> ERROR:: --system is intended to be used for pre-existing Pipfile installation, not installation of specific packages. Aborting.

This is my solution : Remove existing virtualenv

# Check where virtual venv is
pipenv --venv
> /home/0816keisuke/.local/share/virtualenvs/dir_python-5Rka8dPB

# Remove existing virtualenv
cd ~/.local/share/virtualenvs
rm -rf dir_python-5Rka8dPB

# Remake virtualenv
cd ~/dir_python
pipenv --python 3

It's the almost same as MacOS.

Hope this helps you!!

Much appreciated!

rfow-dlpx avatar Aug 30 '22 19:08 rfow-dlpx

Resolví este problema eliminando virtualenv anterior como sigue:

mi entorno

CentOS Linux release 7.9.2009 (Core)
pipenv Version: 2022.4.8
pip Version: 21.3.1

este es nuestro problema

cd dir_python
pipenv --python 3
> Usage: pipenv [OPTIONS] COMMAND [ARGS]...
> ERROR:: --system is intended to be used for pre-existing Pipfile installation, not installation of specific packages. Aborting.

Esta es mi solución: Eliminar virtualenv existente

# Check where virtual venv is
pipenv --venv
> /home/0816keisuke/.local/share/virtualenvs/dir_python-5Rka8dPB

# Remove existing virtualenv
cd ~/.local/share/virtualenvs
rm -rf dir_python-5Rka8dPB

# Remake virtualenv
cd ~/dir_python
pipenv --python 3

Es casi lo mismo que MacOS.

¡¡Espero que esto te ayude!!

This is my solution, change for name the enviorment create

Albertosimplee avatar Aug 31 '22 10:08 Albertosimplee

I solved this by copying pipfile and pipfile.lock to the project folder

Crest22 avatar Sep 12 '22 00:09 Crest22