Having Trouble Creating Virtual Environments

I’m having some difficulty creating a virtual environment using pipenv. I’m working through the pipenv video in the Python Modules section. (Timestamped link to point where I’m having trouble: https://youtu.be/BVr-6Ki96XM?t=808)

Once I’ve selected the correct folder in Microsoft Visual Studio Code, and I call on pipenv using this code: PS C:\Users\user1\Desktop\Python\project-1> pipenv --three, it fails to create a virtual environment. I’m not sure how to parse the error code. It seems like it has something to do with a DLL file not being loaded correctly – I’m not sure if it’s corrupted or needs to be replaced. Does anyone know how to fix this?

Here’s a full copy of the error code I’m seeing:

PS C:\Users\user1\Desktop\Python\project-1> pipenv --three
Creating a virtualenv for this project…
Pipfile: C:\Users\user1\Desktop\Python\project-1\Pipfile
Using C:/Users/user1/AppData/Local/Programs/Python/Python39/python.exe (3.9.1) to create virtualenv…
[= ] Creating virtual environment…
Failed creating virtual environment

[pipenv.exceptions.VirtualenvCreationException]: Traceback (most recent call last):
File “c:\users\user1\anaconda3\lib\runpy.py”, line 185, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File “c:\users\user1\anaconda3\lib\runpy.py”, line 144, in get_module_details
return get_module_details(pkg_main_name, error)
File “c:\users\user1\anaconda3\lib\runpy.py”, line 111, in get_module_details
File "C:\Users\user1\AppData\Roaming\Python\Python38\site-packages\virtualenv_init
.py", line 3, in
from .run import cli_run, session_via_cli
File "C:\Users\user1\AppData\Roaming\Python\Python38\site-packages\virtualenv\run_init
.py", line 11, in
from …seed.wheels.periodic_update import manual_upgrade
File "C:\Users\user1\AppData\Roaming\Python\Python38\site-packages\virtualenv\seed\wheels_init
.py", line 3, in
from .acquire import get_wheel, pip_wheel_env_run
File “C:\Users\user1\AppData\Roaming\Python\Python38\site-packages\virtualenv\seed\wheels\acquire.py”, line 12, in
from .bundle import from_bundle
File “C:\Users\user1\AppData\Roaming\Python\Python38\site-packages\virtualenv\seed\wheels\bundle.py”, line 4, in
from .periodic_update import periodic_update
File “C:\Users\user1\AppData\Roaming\Python\Python38\site-packages\virtualenv\seed\wheels\periodic_update.py”, line 10, in
import ssl
File “c:\users\user1\anaconda3\lib\ssl.py”, line 98, in
import _ssl # if we can’t import it, let the error propagate
ImportError: DLL load failed while importing _ssl: The specified module could not be found.

Failed to create virtual environment.

Any thoughts/suggestions/advice greatly appreciated. Thanks.

Hi there, welcome to the community!

This issue would seem to suggest it’s a problem specific to Anaconda. (I don’t use conda, so can’t attempt to reproduce the issue.)

I have been able to find a topic elsewhere on Stack Overflow, describing a similar issue with the ssl module… so you could try the resolution for that, which is:

  1. Locate the directory for your Anaconda environment. (C:\users\user1\anaconda3)

  2. In the anaconda3\Library\bin folder, locate the following files:*
    2.1 libcrypto-1_1-x64.dll
    2.2 libssl-1_1-x64.dll

  3. Copy these files to anaconda3\DLLs

Again, I don’t use conda (I don’t need prepacked Python modules) so can’t confirm this will work. Proceed with caution. :slight_smile:

This is the thread on SO if you want to look for yourself.

1 Like

That worked! Thank you for helping, I really appreciate it.

Just out of curiosity, what did moving the DLL files do to fix the error?

Moving the DLL files placed them in the folder where (I presume) Anaconda expects them to be, or at least to a folder which is included in Anaconda’s search path for loading modules. :slight_smile:

Got it, thanks! Appreciate it.