pipenv: FileNotFoundError: [Errno 2] when installing pipenv from pipfile

Hi all,

I am experiencing some issues while building my docker file on the last shown step (1):

COPY Pipfile* ./
RUN pip3 install pipenv
(1) RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy --clear --keep-outdated.

I get the following Stacktrace:

 > [builder-image 5/5] RUN pipenv install --deploy --clear --keep-outdated:                                                                                                                                                    
#10 1.527 Creating a virtualenv for this project...                                                                                                                                                                            
#10 1.527 Pipfile: /Pipfile                                                                                                                                                                                                    
#10 1.543 Using /usr/bin/python3 (3.10.4) to create virtualenv...                                                                                                                                                              
⠼ Creating virtual environment...created virtual environment CPython3.10.4.final.0-64 in 491ms                                                                                                                                 
#10 2.680   creator CPython3Posix(dest=/.venv, clear=False, no_vcs_ignore=False, global=False)
#10 2.680   seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv)
#10 2.680     added seed packages: pip==22.0.4, setuptools==62.1.0, wheel==0.37.1
#10 2.680   activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
#10 2.680 
#10 2.758✔ Successfully created virtual environment! 
#10 2.760 Traceback (most recent call last):
#10 2.760   File "/usr/local/bin/pipenv", line 8, in <module>
#10 2.760     sys.exit(cli())
#10 2.760   File "/usr/local/lib/python3.10/dist-packages/pipenv/vendor/click/core.py", line 1128, in __call__
#10 2.761     return self.main(*args, **kwargs)
#10 2.761   File "/usr/local/lib/python3.10/dist-packages/pipenv/cli/options.py", line 56, in main
#10 2.761     return super().main(*args, **kwargs, windows_expand_args=False)
#10 2.761   File "/usr/local/lib/python3.10/dist-packages/pipenv/vendor/click/core.py", line 1053, in main
#10 2.761     rv = self.invoke(ctx)
#10 2.761   File "/usr/local/lib/python3.10/dist-packages/pipenv/vendor/click/core.py", line 1659, in invoke
#10 2.762     return _process_result(sub_ctx.command.invoke(sub_ctx))
#10 2.764   File "/usr/local/lib/python3.10/dist-packages/pipenv/vendor/click/core.py", line 1395, in invoke
#10 2.765     return ctx.invoke(self.callback, **ctx.params)
#10 2.765   File "/usr/local/lib/python3.10/dist-packages/pipenv/vendor/click/core.py", line 754, in invoke
#10 2.765     return __callback(*args, **kwargs)
#10 2.766   File "/usr/local/lib/python3.10/dist-packages/pipenv/vendor/click/decorators.py", line 84, in new_func
#10 2.766     return ctx.invoke(f, obj, *args, **kwargs)
#10 2.766   File "/usr/local/lib/python3.10/dist-packages/pipenv/vendor/click/core.py", line 754, in invoke
#10 2.767     return __callback(*args, **kwargs)
#10 2.767   File "/usr/local/lib/python3.10/dist-packages/pipenv/cli/command.py", line 222, in install
#10 2.767     do_install(
#10 2.767   File "/usr/local/lib/python3.10/dist-packages/pipenv/core.py", line 1964, in do_install
#10 2.768     ensure_project(
#10 2.768   File "/usr/local/lib/python3.10/dist-packages/pipenv/core.py", line 552, in ensure_project
#10 2.770     ensure_virtualenv(
#10 2.770   File "/usr/local/lib/python3.10/dist-packages/pipenv/core.py", line 485, in ensure_virtualenv
#10 2.770     do_create_virtualenv(
#10 2.770   File "/usr/local/lib/python3.10/dist-packages/pipenv/core.py", line 1012, in do_create_virtualenv
#10 2.771     project._environment = Environment(
#10 2.772   File "/usr/local/lib/python3.10/dist-packages/pipenv/environment.py", line 70, in __init__
#10 2.772     self._base_paths = self.get_paths()
#10 2.773   File "/usr/local/lib/python3.10/dist-packages/pipenv/environment.py", line 394, in get_paths
#10 2.774     c = subprocess_run(command)
#10 2.774   File "/usr/local/lib/python3.10/dist-packages/pipenv/utils/processes.py", line 75, in subprocess_run
#10 2.774     return subprocess.run(
#10 2.775   File "/usr/lib/python3.10/subprocess.py", line 501, in run
#10 2.775     with Popen(*popenargs, **kwargs) as process:
#10 2.775   File "/usr/lib/python3.10/subprocess.py", line 966, in __init__
#10 2.776     self._execute_child(args, executable, preexec_fn, close_fds,
#10 2.778   File "/usr/lib/python3.10/subprocess.py", line 1842, in _execute_child
#10 2.778     raise child_exception_type(errno_num, err_msg, err_filename)
#10 2.778 FileNotFoundError: [Errno 2] No such file or directory: '/.venv/bin/python'
------
executor failed running [/bin/sh -c pipenv install --deploy --clear --keep-outdated]: exit code: 1

The solution I found is:

COPY Pipfile* ./
RUN pip3 install pipenv==v2022.4.20
RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy --clear --keep-outdated

The build image is ubuntu:22.04, python-version 3.10.4

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 11
  • Comments: 65 (24 by maintainers)

Commits related to this issue

Most upvoted comments

The (excellent!) bug report at https://github.com/pypa/setuptools/issues/3278 identifies the cause more precisely.

There are two better workarounds identified there:

  • Set the environment variable SETUPTOOLS_USE_DISTUTILS=stdlib when running pipenv.
  • Or change the default setting in a file with sed -i.bak -e "s/var, 'local'/var, 'stdlib'/" ~/.local/lib/python3.10/site-packages/distutils-precedence.pth

@andrewdotn I had to export in order for it to work:

export SETUPTOOLS_USE_DISTUTILS=stdlib

Bump ino this error on Ubuntu 22.04 Python 3.10.4 even after export SETUPTOOLS_USE_DISTUTILS=stdlib and upgraded setuptools.

$ pip install --upgrade --user setuptools
Requirement already satisfied: setuptools in /home/khteh/.local/lib/python3.10/site-packages (61.0.0)
Collecting setuptools
  Downloading setuptools-62.2.0-py3-none-any.whl (1.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.1/1.1 MB 17.8 MB/s eta 0:00:00
Installing collected packages: setuptools
  Attempting uninstall: setuptools
    Found existing installation: setuptools 61.0.0
    Uninstalling setuptools-61.0.0:
      Successfully uninstalled setuptools-61.0.0
Successfully installed setuptools-62.2.0
$ pipenv install
/home/khteh/.local/lib/python3.10/site-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: 1.1build1 is an invalid version and will not be supported in a future release
  warnings.warn(
/home/khteh/.local/lib/python3.10/site-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: 0.1.43ubuntu1 is an invalid version and will not be supported in a future release
  warnings.warn(
Installing dependencies from Pipfile.lock (cb1e45)...
Traceback (most recent call last):
  File "/home/khteh/.local/bin/pipenv", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.10/dist-packages/pipenv/vendor/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/pipenv/cli/options.py", line 56, in main
    return super().main(*args, **kwargs, windows_expand_args=False)
  File "/usr/local/lib/python3.10/dist-packages/pipenv/vendor/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.10/dist-packages/pipenv/vendor/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.10/dist-packages/pipenv/vendor/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.10/dist-packages/pipenv/vendor/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/pipenv/vendor/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/pipenv/vendor/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/pipenv/cli/command.py", line 222, in install
    do_install(
  File "/usr/local/lib/python3.10/dist-packages/pipenv/core.py", line 2091, in do_install
    do_init(
  File "/usr/local/lib/python3.10/dist-packages/pipenv/core.py", line 1335, in do_init
    do_install_dependencies(
  File "/usr/local/lib/python3.10/dist-packages/pipenv/core.py", line 870, in do_install_dependencies
    batch_install(
  File "/usr/local/lib/python3.10/dist-packages/pipenv/core.py", line 728, in batch_install
    deps_to_install = [
  File "/usr/local/lib/python3.10/dist-packages/pipenv/core.py", line 729, in <listcomp>
    dep for dep in deps_to_install if not project.environment.is_satisfied(dep)
  File "/usr/local/lib/python3.10/dist-packages/pipenv/project.py", line 319, in environment
    self._environment = self.get_environment(allow_global=allow_global)
  File "/usr/local/lib/python3.10/dist-packages/pipenv/project.py", line 299, in get_environment
    environment = Environment(
  File "/usr/local/lib/python3.10/dist-packages/pipenv/environment.py", line 70, in __init__
    self._base_paths = self.get_paths()
  File "/usr/local/lib/python3.10/dist-packages/pipenv/environment.py", line 394, in get_paths
    c = subprocess_run(command)
  File "/usr/local/lib/python3.10/dist-packages/pipenv/utils/processes.py", line 75, in subprocess_run
    return subprocess.run(
  File "/usr/lib/python3.10/subprocess.py", line 501, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/lib/python3.10/subprocess.py", line 966, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.10/subprocess.py", line 1842, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/home/khteh/.local/share/virtualenvs/PythonRestAPI-JI5RzKtM/bin/python'

Why is this closed?

/open

For those mortals here who are still confused and questioning–“what commands do I run to fix this…” which was definitely not moi, try,

pip install --upgrade --user setuptools==58.3.0

I am having the same issue on the new Ubuntu 22.04 but not the previous 21.10.

I do not understand the problem but I have identified a workaround: pip uninstall -y setuptools seems to allow pipenv to run.

I can reproduce the issue without pipenv. Something about the act of installing the setuptools dependency specified in pipenv’s setup.py breaks virtualenv creation on Ubuntu 22.04; no bin dir gets created.

FROM ubuntu:22.04

RUN apt update \
    && DEBIAN_FRONTEND=noninteractive apt install -y python3-pip \
    && rm -rf /var/lib/apt/lists

RUN adduser  user1

USER user1
WORKDIR /home/user1

RUN pip install --user virtualenv 'setuptools>=60.0.0'
RUN python3 -m virtualenv foo && foo/bin/python3 --version

fails with /bin/sh: 1: foo/bin/python3: not found

none of the above worked for me, what worked was simply removing the already created venv: pipenv --rm

Remove ~/.local/share/virtualenvs/* works for me.

@andrewdotn the SETUPTOOLS_USE_DISTUTILS=stdlib also worked for me.

THIS WORKED FOR ME

I’m still facing this issue in Ubuntu 22.04 too. Removing ~/.local/share/virtualenvs/ followed by export SETUPTOOLS_USE_DISTUTILS=stdlib works for me as a temporary workaround. Warnings are still there.

jixbo@thinkpad:~$ pip --version
pip 22.1.2 from /home/jixbo/.local/lib/python3.10/site-packages/pip (python 3.10)
jixbo@thinkpad:~$ python --version
Python 3.10.4
jixbo@thinkpad:~$ which python
/usr/bin/python

I was getting the same FileNotFoundError alongwith two PkgResourcesDeprecationWarning.

See warnings
~/.local/lib/python3.10/site-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: 0.1.43ubuntu1 is an invalid version and will not be supported in a future release
  warnings.warn(
~/.local/lib/python3.10/site-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: 1.1build1 is an invalid version and will not be supported in a future release
  warnings.warn(

Searching for the origin of those warnings, I stumbled upon this StackOverflow question. Following the accepted answer, I downgraded setuptools from version 65.3.0 to version 58.3.0:

pip install --upgrade --user setuptools==58.3.0

After that, I rerun pipenv install and everything worked properly: a bin/python path was found within the virtualenvs directory, and no warnings were issued.

  • Ubuntu 22.04.1 LTS
  • Python 3.10.4
  • Pip 22.2.2
  • Pipenv 2022.8.24

@andrewdotn I had to export in order for it to work:

export SETUPTOOLS_USE_DISTUTILS=stdlib

This worked for me as well.

System Information:

Python

Python 3.10.4
pipenv, version 2022.4.20

Kernel

Linux cj-Z 5.15.0-25-generic #25-Ubuntu SMP Wed Mar 30 15:54:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Ubuntu:

Distributor ID: Ubuntu
Description:    Ubuntu 22.04 LTS
Release:        22.04
Codename:       jammy

Thank you. exporting solved my issue

I don’t think the version of pip affects this?

When the setuptools/virtualenv/distutils bug is resolved then pipenv can depend on the newer version of those.

The difference between 2022.4.20 and 2022.4.21 is that it requires setuptools>=60 which has this problem. Ubuntu 22.04 was also released around the same time.

@oz123 Appears to work:

matteius@matteius-VirtualBox:~/pipenv$ sudo apt remove python3-venv
[sudo] password for matteius: 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
  systemd-hwe-hwdb
Use 'sudo apt autoremove' to remove it.
The following packages will be REMOVED:
  python3-venv
0 upgraded, 0 newly installed, 1 to remove and 17 not upgraded.
After this operation, 6,144 B disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 297188 files and directories currently installed.)
Removing python3-venv (3.10.6-1~22.04) ...
matteius@matteius-VirtualBox:~/pipenv$ pipenv --rm
Removing virtualenv (/home/matteius/.virtualenvs/pipenv-wR0g04D-)...
matteius@matteius-VirtualBox:~/pipenv$ pipenv sync -d
Creating a virtualenv for this project...
Pipfile: /home/matteius/pipenv/Pipfile
Using /usr/bin/python3 (3.10.6) to create virtualenv...
⠸ Creating virtual environment...created virtual environment CPython3.10.6.final.0-64 in 222ms
  creator Venv(dest=/home/matteius/.virtualenvs/pipenv-wR0g04D-, clear=False, no_vcs_ignore=False, global=False, describe=CPython3Posix)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/matteius/.local/share/virtualenv)
    added seed packages: pip==22.2.2, setuptools==65.3.0, wheel==0.37.1
  activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator

✔ Successfully created virtual environment! 
Virtualenv location: /home/matteius/.virtualenvs/pipenv-wR0g04D-
Installing dependencies from Pipfile.lock (ccf32d)...
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.
All dependencies are now up-to-date!
matteius@matteius-VirtualBox:~/pipenv$ pipenv shell
Launching subshell in virtual environment...
 . /home/matteius/.virtualenvs/pipenv-wR0g04D-/bin/activate
matteius@matteius-VirtualBox:~/pipenv$  . /home/matteius/.virtualenvs/pipenv-wR0g04D-/bin/activate
(pipenv-wR0g04D-) matteius@matteius-VirtualBox:~/pipenv$ 

pipenv install --python=/path/to/python resoves it.

Mentioning this issue again in case you haven’t seen the write up. https://github.com/pypa/setuptools/issues/3278

I was able to get unblocked by following the steps mentioned in @andrewdotn’s post, https://github.com/pypa/pipenv/issues/5075#issuecomment-1107460002, and blowing away my existing pipenv in ~/.local/share/virtualenvs/MY_PROJECT then recreating the env.

@khteh I can’t reproduce that, are you able to provide a script that does so in a fresh container or VM? The following Dockerfile works for me and uses the latest ubuntu, Python, pipenv==2022.5.2, and setuptools==62.2.0:

FROM ubuntu:22.04

RUN apt update \
    && DEBIAN_FRONTEND=noninteractive apt install -y python3-pip git \
    && rm -rf /var/lib/apt/lists

RUN adduser  user1

USER user1
WORKDIR /home/user1

RUN pip install --user pipenv
RUN pip install -U --user setuptools==62.2.0
RUN touch Pipfile && SETUPTOOLS_USE_DISTUTILS=stdlib python3 -m pipenv install
RUN python3 -m pipenv run which python && python3 -m pipenv run python --version

@andrewdotn I had to export in order for it to work:

export SETUPTOOLS_USE_DISTUTILS=stdlib

This worked for me as well.

System Information:

Python

Python 3.10.4
pipenv, version 2022.4.20

Kernel

Linux cj-Z 5.15.0-25-generic #25-Ubuntu SMP Wed Mar 30 15:54:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Ubuntu:

Distributor ID: Ubuntu
Description:    Ubuntu 22.04 LTS
Release:        22.04
Codename:       jammy

@felipecrp its definitely been reported before the new versions about the warnings for pkg_resources. Here is an example, and there are a couple more if you search the closed issues: https://github.com/pypa/pipenv/issues/4960

@andrewdotn this worked for me 😃 @matteius yes, from one day to other it did not work…