54

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. 
3
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Commented Oct 25, 2021 at 14:15
  • Seems there are no hits for "failed to create virtual environment". However, there are some hits for "failed to create interpreter". Please edit the question to show the exact options like in this answer. Commented Oct 25, 2021 at 20:12
  • 3
    I had the same problem. I needed to install package python3.10-venv. Commented Jan 15, 2022 at 9:52

26 Answers 26

25

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

Sign up to request clarification or add additional context in comments.

1 Comment

how to install python3-venv in windows
24

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

pip install virtualenv 

After installing the virtualenv package everything works as expected.

Comments

12

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.

Comments

9

I attempted the previous answers and eventually found that I had to delete the venv folder and allow PyCharm to recreate it.

1 Comment

did you simply force delete the folder or there is any safer way?
8

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

Comments

6

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

1 Comment

While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
5

A possible reason could be not having the package virtualevn installed in your computer. I had the problem after reinstalling OS.

The following is valid for ubuntu OS with Python3 installed.

Check if the pip is installed after installing Python. Use the command sudo apt install python3-pip.

Once pip installed, install the package using pip3 install virtualenv. Then go back to Pycharm IDE settings to set up the venv.

Comments

2

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

enter image description here

1 Comment

This answer would likely be more helpful to future readers if you also outlined the steps necessary to manually add an interpreter.
2

In my case i wasn't the owner of the project file. I was needed to run the CHOWN command to resolve this.

sudo chown $USER /Users/Sites/***<Project_Folder>***

and i was done.

Comments

2

In my case, there was something wrong with the latest PyCharm Community Edition of 2022.2.3 version (build ID: 222.4345.23). I tried everything mentioned here with no vain. After spending several hours, just downgraded to version 2021.3.2 version of PyCharm community edition, and it just worked. Hope this helps.

Comments

2

I faced the same problem. In my case, algorithm of solution was as follows:

  1. Check PyCharm Log (Help > Show Log in Explorer)

  2. According to the log the problem was:

2022-12-18 19:20:04,774 [1212498] WARN - #c.j.p.s.PySdkUtil - Charset x-windows-950 is not UTF-8, which is likely lead to troubles

  1. In my Win10 Administrative panel I enabled UTF-8: Region and Language > Administrative > Change system locale... > Check the checkbox Beta: Use Unicode UTF-8 for worldwide language support.

  2. Restart Windows.

In my case problem was solved.

Comments

1

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.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
1

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.

Comments

1

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

Comments

1

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'

Comments

1

I had same problem tried many things But I realized that Window Defender is blocking PyCharm to create virtual environment

Just go in Defender Settings and allow PyChram

Comments

1

I had same issue with following version.

pycharm - PyCharm 2022.1.3 (Community Edition) python - python 3.9

Once I changed interpreter version to python 3.10. It started working.

Comments

1

I ran into the same problem, but was able to resolve it in my environment.

Go to Help -> Edit Custom VM Options and add the following

-Dfile.encoding=UTF-8 

Here is my environment:

Windows 11 PyCharm Community 2022.2.3 (installed from JetBrains ToolBox) Python 3.11 (installed from microsoft store) 

Comments

1

I had the same error and I don't know how the solution that I'll explain solved I was naming the project as "Joining Data with pandas", "joining_data_with_pandas"

but when I changed the name to "joiningDataPandas", it works with no error.

I think it may be a bug from the ide or something, because if I tried to create a new project with the old name that has spaces or "_" the error will be back, but with writing the project name with the camelCase, there is no error.

Comments

1
  1. Open and clear the log: %AppData%\Local\JetBrains\PyCharmCE2022.1\log\idea.log (in PyCharm click Help > Show Log in Explorer).

  2. Try to create VirtualEnv via PyCharm, you will see the "Failed to create Venv..." message screenshot

  3. Open the log and look for errors log error example In my case it was unable to import some modules because the threading module was not found (ie: ModuleNotFoundError: No module named 'threading'). My python3.10 was broken, maybe I have some problems with my PATH variable.

  4. I was missing the modules threading, logging, and weakref, so I just copied them to %AppData%\Local\Programs\Python\Python310\Lib\ (from site-packages folder, in my case)

  5. Enjoy creating as many VENV's as you needed. If you still have an error in PyCharm then repeat steps 2, 3, and 4 until you fix all errors about missing modules or other.

Comments

1

I fixed this problem by first deleting my current venv folder. Then I went back to PyCharm to Configure Local Environment>Add Local Interpreter> and made sure the location is in an empty directory. I did this by just adding /venv at the end of my path.

Comments

1

In my case, the command pip install virtualenv didn't work.

I have two python version (3.9 and 3.10)

It shows "failed to create a virtual environment pycharm" while I trying to replace with python(3.10) as Interpreter.

This is my step: Uninstall old python(3.9), and uninstall PyCharm 2021.1.3 Download and install latest PyCharm, than it specify python(3.10) in my computer automaticallly!

Comments

1

For me, I had to follow the instructions here (https://www.jetbrains.com/help/pycharm/pipenv.html)

pip install pipenv 

Comments

1

I ended up needing to pip install setuptools on the (newly installed) base interpreter. In the interpreter settings, I wasn't seeing any packages and was seeing a notification like this.

enter image description here

When I clicked the button to install packaging tools, I was presented an error related to the installation of setuptools. Manually triggering that installation let me install packaging tools and resolved venv creation.

Comments

0

You should create virtualenv manually

  1. Open pycharm
  2. File >> Settings >> Project: (your project name) >> Python Interpreter
  3. Click on Add interpreter >> Add local Interpreter
  4. Click on Virtualenv Environment
  5. Environment : click on New
  6. Location : your project location
  7. Base Interpreter : python location
  8. Click on OK

That's it. Your virtual environment is created

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
0

after trying all solutions above I changed python interpreter version in setting and it works for me enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.