Problems trying to create a virtual environment with pipenv

Asked

Viewed 1,629 times

4

I’m having a hard time creating a virtual environment with pipenv, I installed it without problems with the Pip, the problem happens at the time of creating the environment.
I’m using Windows 10 and Python 3.7.

I tried to install the pipenv using the command:

pip install pipenv

The installation did not show errors, but it gave problem when trying to create the environment. So I uninstalled everything and tried with:

pip install --user pipenv

Adjusting the environment variables as explained in the documentation, but also gave error when trying to create the environment.
I tried to create the virtual environment with the following commands:

pipenv install
pipenv install django
pipenv --three

What comes back to me:

    Creating a virtualenv for this project…
    Pipfile: C:\python\projeto\Pipfile
    Using c:\users\usuário\appdata\local\programs\python\python37-32\python.exe 
    (3.7.0) to create virtualenv…
    [=== ] Creating virtual environment...Already using interpreter 
    c:\users\usuário\appdata\local\programs\python\python37-32\python.exe
    Using base prefix 
    'c:\\users\\usuário\\appdata\\local\\programs\\python\\python37-32'
    New python executable in C:\python\projeto\.venv\Scripts\python.exe
    Installing setuptools, pip, wheel...
    Complete output from command C:\python\projeto\.venv\Scripts\python.exe - 
    setuptools pip wheel:
    Traceback (most recent call last):
    File "<stdin>", line 3, in <module>
    ModuleNotFoundError: No module named 'pkgutil'
    ----------------------------------------
    ...Installing setuptools, pip, wheel...done.
    Failed creating virtual environment
    [pipenv.exceptions.VirtualenvCreationException]:   File 
    "c:\users\usuário\appdata\local\programs\python\python37-32\lib\site- 
   packages\pipenv\cli\command.py", line 254, in install
    [pipenv.exceptions.VirtualenvCreationException]:       
    editable_packages=state.installstate.editables,
    [pipenv.exceptions.VirtualenvCreationException]:   File 
    "c:\users\usuário\appdata\local\programs\python\python37-32\lib\site- 
   packages\pipenv\core.py", line 1741, in do_install
    [pipenv.exceptions.VirtualenvCreationException]:       
    pypi_mirror=pypi_mirror,
    [pipenv.exceptions.VirtualenvCreationException]:   File 
    "c:\users\usuário\appdata\local\programs\python\python37-32\lib\site- 
   packages\pipenv\core.py", line 574, in ensure_project
    [pipenv.exceptions.VirtualenvCreationException]:       
    pypi_mirror=pypi_mirror,
    [pipenv.exceptions.VirtualenvCreationException]:   File 
    "c:\users\usuário\appdata\local\programs\python\python37-32\lib\site- 
   packages\pipenv\core.py", line 506, in ensure_virtualenv
    [pipenv.exceptions.VirtualenvCreationException]:       python=python, 
    site_packages=site_packages, pypi_mirror=pypi_mirror
    [pipenv.exceptions.VirtualenvCreationException]:   File 
    "c:\users\usuário\appdata\local\programs\python\python37-32\lib\site- 
   packages\pipenv\core.py", line 935, in do_create_virtualenv
    [pipenv.exceptions.VirtualenvCreationException]:       extra=[crayons.blue(" 
   {0}".format(c.err)),]
    [pipenv.exceptions.VirtualenvCreationException]: Traceback (most recent call 
    last):
    File "c:\users\usuário\appdata\local\programs\python\python37- 
   32\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
    File "c:\users\usuário\appdata\local\programs\python\python37- 
   32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
    File "c:\users\usuário\appdata\local\programs\python\python37-32\lib\site- 
   packages\virtualenv.py", line 2462, in <module>
    main()
    File "c:\users\usuário\appdata\local\programs\python\python37-32\lib\site- 
   packages\virtualenv.py", line 762, in main
    symlink=options.symlink,
    File "c:\users\usuário\appdata\local\programs\python\python37-32\lib\site- 
   packages\virtualenv.py", line 1015, in create_environment
    install_wheel(to_install, py_executable, search_dirs, download=download)
    File "c:\users\usuário\appdata\local\programs\python\python37-32\lib\site- 
   packages\virtualenv.py", line 968, in install_wheel
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
    File "c:\users\usuário\appdata\local\programs\python\python37-32\lib\site- 
   packages\virtualenv.py", line 854, in call_subprocess
    raise OSError("Command {} failed with error code {}".format(cmd_desc, 
    proc.returncode))
    OSError: Command C:\python\projeto\.venv\Scripts\python.exe - setuptools pip 
    wheel failed with error code 1
    Failed to create virtual environment.

That question here did not help me much in this problem.

Someone has a light?

3 answers

3


I’ll leave here the solution I found, may be useful to someone else.
I tried to create a direct virtual environment with the virtualenv, since the pipenv uses it under the cloths
virtualenv . venv
but this was showing error, I even tried to reinstall Pip and virtualenv but it didn’t work. As I already used the venv which comes by default in Python, I solved the problem by creating the environment through it
python -m venv . venv
and from there I’m using the pipenv normally smoothly
pipenv shell
pipenv install Django

It is possible that not everything in the pipenv works properly, but for the basic commands of installation and uninstallation of dependencies, generation of pipfile and other things that I am using so far is working smoothly.

2

There is a question similar to yours on Soen.

There it is raised that maybe you have a broken installation of 'Pip' and it is recommended to open Pip and install again. I’m not a big fan of that kind of answer, but it might work in your case. Also check if you can install the virtual environment unused the pipenv, ie using only Pip.

pip install virtualenv

If you fail and the same error occurs, it is very likely that it is actually an internal problem with the files of your Pip version.

One last little tip. If you are going to work with Django, always try to use a stable version of python. I see that this using python 3.7, at the moment has a small compatibility bug between some versions of Django and python 3.7.

Then, preceding possible problems, if an error similar to that Django has a fix for the same , feel free to use it.

I hope I’ve helped.

  • 1

    Thanks for the Django version tip! Regarding pipenv, I noticed that virtualenv gives this problem, so I tried to create the environment using venv and at first it is working well.

0

The tip above was perfect! Congratulations and thanks, @Gau

After uninstalling pipenv...

 pip uninstall pipenv

done...

python -m venv .venv

afterward...

pip install pipenv

and in sequence...

pipenv shell

pipenv install selenium

proceeding finally with the desired installation, thus eliminated with the error code 1 recurring

 Installing selenium… Adding selenium to Pipfile's [packages]…
 Installation Succeeded Pipfile.lock not found, creating… Locking
 [dev-packages] dependencies… Locking [packages] dependencies… Success!
 Updated Pipfile.lock (2bb13d)! Installing dependencies from
 Pipfile.lock (2bb13d)…

Browser other questions tagged

You are not signed in. Login or sign up in order to post.