简体   繁体   中英

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?

在此处输入图像描述


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.

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

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

pip install virtualenv

After installing the virtualenv package everything works as expected.

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

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.

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

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.

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.

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.

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.

if you don't have pip before install pip

sudo apt install python3-pip

press Ctrl + Alt + S

在此处输入图像描述

then click settings button and select show all

在此处输入图像描述

press Alt + Insert keys then

在此处输入图像描述

Select Virtualenv Environment and check Inherit global site-packages

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

在此处输入图像描述

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'

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

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.

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.

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

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)

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.

  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截屏

  3. Open the log and look for errors日志错误示例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.

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.

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 - #cjpsPySdkUtil - Charset x-windows-950 is not UTF-8, which is likely lead to troubles"
  3. 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.
  4. Restart Windows.

In my case problem was solved.

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 create

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM