'Failed to create virtual environment in PyCharm

I have problem with create virtual environment in PyCharm. Exactly, Python in version 3.10 was add to Path during installation and I use latest version PyCharm community.

Did anyone have a similar problem?

enter image description here


Adding Informations

How I create environment :

  • file -> New project

  • Location : D:\mm\projekty\pythonProject2

  • marked New virtual environment using ( virtualenv)

  • Location : D:\mm\projekty\pythonProject2\venv

  • Base interpreter : C:\Users\mm\AppData\Local\Programs\Python\Python310\python.exe

  • In CMD:

    C:\Users\mm>python
    
    Python 3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    


Solution 1:[1]

I had the same problem. I needed to install package python3-venv.

Solution 2:[2]

In order to fix this, I had to run from my terminal:

pip install virtualenv

After installing the virtualenv package everything works as expected.

Solution 3:[3]

In my case, I didn't have pip installed on my computer.

Solution 4:[4]

If you have python3-env already installed, the commands provided in most of the answers will not work as you need the python3-venv package specifically for Python 3.10

The exact package as pointed by @fabel in comments is python3.10-venv .

sudo apt install python3.10-venv

Run this command and it should be good to go.

Solution 5:[5]

just open your terminal and install pip package:

In ubuntu: sudo apt install pip

For windows: https://phoenixnap.com/kb/install-pip-windows

Then try to create the virtual environment again

Solution 6:[6]

I ran "pip install virtualenv" in the terminal, but after trying again it didn't work. I downloaded python 3.10 from python.org then because i had problems updating my python version from 3.9 to 3.10 on my computer, i decided to try to make a virtual environment in PyCharm, in my main project (my only one) I clicked "Add Interpreter..." then selected "Virtualenv environment" then set the location to "/home/myname/Documents/PyCharm/venvPy3.10" and then i set base interpreter to the one i downloaded by clicking on the three dots on the right of it then going to my downloads folder. I also selected both "Inherit global site-packages" and "Make available to all project" then clicked "OK". Then it gives me warning.

Solution 7:[7]

There is a bug in Windows venv, which is known to be exposed if you install a VisualStudio 2022 runtime. If PyCharm uses venv and not another virtual environment (not sure as I don't use PyCharm) s See if my issue/workaround in this Q&A aligns with yours.

Edit: I realize that you are using virtualenv instead. However, virtualenv uses venv.EnvBuilder so the issue could still be related.

Solution 8:[8]

if you don't have pip before install pip

sudo apt install python3-pip

press Ctrl + Alt + S

enter image description here

then click settings button and select show all

enter image description here

press Alt + Insert keys then

enter image description here

Select Virtualenv Environment and check Inherit global site-packages

Solution 9:[9]

I had the same problem, but solved it by adding an interpreter manually.

enter image description here

Solution 10:[10]

If someone is still not able to fix this then, create it manually.

  1. go in the dir that you want the venv in, then python3.10 -m venv <name of venv>
  2. source <name of venv>/bin/activate
  3. go in Python Interpeter settings and then select the location of the manually created venv in the 'existing environment'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ceperman
Solution 2 Dmitry Papka
Solution 3 UFO
Solution 4 ezvine
Solution 5 David Maya
Solution 6 user17526287
Solution 7
Solution 8 Tolga Sahin
Solution 9 Henry Ecker
Solution 10 SimSimSim