Problems trying to create a virtual environment with pipenv

3

I'm having trouble creating a virtual environment with pipenv , I installed it without problems with pip , the problem happens when creating the environment. > I'm using Windows 10 and Python 3.7.

I tried to install pipenv using the command:

pip install pipenv

The installation did not show any errors, but gave trouble 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 failed to create the environment. I tried to create the virtual environment with the following commands:

pipenv install
pipenv install django
pipenv --three

What returns 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.

This question does not helped a lot in this problem.

Does anyone have a light?

    
asked by anonymous 05.12.2018 / 16:12

2 answers

2

I'll leave here the solution I found, it might be useful for someone else. I've tried to create a virtual environment directly with virtualenv , since pipenv uses it underneath the virtualenv .venv
but this was showing error, I even tried to reinstall the pip and virtualenv but it did not work. As I already used venv that comes by default in Python, I solved the problem by creating the environment through it
python -m venv .venv
and from there I am using pipenv normally without problems pipenv shell
pipenv install django

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

    
15.12.2018 / 12:42
2

There's a question similar to yours in SOen .

There it is raised that you may have a broken installation of 'pip' and it is recommended to uninstall the pip and install again. I'm not much of a fan of that kind of response, but it might work for you. Also check if you can install the virtual environment without using pipenv, ie using only the pip.

pip install virtualenv

If you do not get and the same error occurs, it is probably likely to be an internal problem with your pip version files.

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

So before possible problems, if an error similar to this django has a fix for the same, feel free to use it.

I hope I have helped.

    
05.12.2018 / 17:32