无法在PyCharm中创建虚拟环境(Python 3.4)

huangapple go评论75阅读模式
英文:

Failed to create virtual environment in PyCharm (Python 3.4 )

问题

我正在进行一个项目,需要使用Python 3.4,因为需要使用十年未维护的旧模块。为此,我尝试在Pycharm中创建一个虚拟环境,但一直无法成功。如果有人可以帮助我,我将非常感激!!!

我尝试像这样创建一个环境(由于隐私原因,项目文件夹已隐藏):

然后结果是这个错误消息:

我已经按照另一个帖子中的建议进行了操作,这是我的日志文件转储:

从我所能看到的,可能有很多问题会导致这个错误。我不知道是哪一个问题,是否与Python 3.4 特别相关,还是与我的PyCharm安装有关。如果有人可以帮助,非常感谢!我卡住了,不能继续这个项目!

英文:

I'm working on a project which requires Python 3.4 due to needing old modules which have not been maintained in ten years. For this I'm trying to create a virtual environment in Pycharm, but it's not been working. I'd be super grateful if someone can help me out!!!

I try to create an environment like this (project folders obscured for privacy reasons):
无法在PyCharm中创建虚拟环境(Python 3.4)

Then the result is this error message:
无法在PyCharm中创建虚拟环境(Python 3.4)

I have followed suggestions in another thread and this is a dump of my log file:

2023-05-28 19:37:12,477 [1924503]   INFO -
#c.j.p.p.PyCondaPackageService - Using D:\Codes\anaconda3\Scripts\conda.exe as a conda executable (specified as a preferred conda path) 2023-05-28 19:37:12,477 [1924503]   INFO -
#c.j.p.p.PyCondaPackageService - Using D:\Codes\anaconda3\Scripts\conda.exe as a conda executable (specified as a preferred conda path) 2023-05-28 19:37:12,477 [1924503]   INFO -
#c.j.p.p.PyCondaPackageService - Using D:\Codes\anaconda3\Scripts\conda.exe as a conda executable for D:/Codes/anaconda3/python.exe (found as a relative to the env) 2023-05-28 19:37:15,915 [1927941]   INFO -
#c.j.p.p.PyPackageManagerImpl - Running packaging tool: D:\Codes\Python3.4.4\python.exe -S D:\Codes\PyCharm Community Edition
2022.2\plugins\python-ce\helpers\virtualenv.pyz D:\-----\Pycharm_Projects\-----\venv 2023-05-28 19:37:16,243 [1928269] INFO - #c.j.p.p.PyPackageManagerImpl - Exit code 1 2023-05-28 19:37:16,243 [1928269]   INFO - #c.j.p.p.PyPackageManagerImpl - Traceback (most recent call last):   File "D:\Codes\Python3.4.4\lib\runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)   File "D:\Codes\Python3.4.4\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)   File "D:\Codes\PyCharm Community Edition 2022.2\plugins\python-ce\helpers\virtualenv.pyz\__main__.py", line 167, in <module>   File "D:\Codes\PyCharm Community Edition
2022.2\plugins\python-ce\helpers\virtualenv.pyz\__main__.py", line 161, in run   File "<frozen importlib._bootstrap>", line 2237, in
_find_and_load   File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked   File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked   File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible   File "D:\Codes\PyCharm Community Edition
2022.2\plugins\python-ce\helpers\virtualenv.pyz\virtualenv\__init__.py", line 3, in <module>   File "<frozen importlib._bootstrap>", line 2237, in _find_and_load   File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked   File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked   File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible   File "D:\Codes\PyCharm Community Edition
2022.2\plugins\python-ce\helpers\virtualenv.pyz\virtualenv\run\__init__.py", line 7, in <module>   File "<frozen importlib._bootstrap>", line 2237, in _find_and_load   File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked   File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked   File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible   File "D:\Codes\PyCharm Community Edition
2022.2\plugins\python-ce\helpers\virtualenv.pyz\virtualenv\app_data\__init__.py", line 9, in <module>   File "D:\Codes\PyCharm Community Edition
2022.2\plugins\python-ce\helpers\virtualenv.pyz\__virtualenv__/platformdirs-2.4.1-py3-none-any/platformdirs/__init__.py", line 29
    result: type[PlatformDirsABC] = getattr(importlib.import_module(module), name)
          ^ SyntaxError: invalid syntax

2023-05-28 19:37:17,035 [1929061]   INFO - #c.i.u.EnvironmentUtil - shell environment loaded (56 vars) 2023-05-28 19:37:19,121 [1931147]   INFO - #c.i.c.ComponentStoreImpl - Saving appFileTypeManager took 15 ms

From what I can tell, there are any number of issues that could cause this. I have no clue which one, and if it is related to Python 3.4 specifically or my PyCharm installation or what. If anyone can help, thank you so much! I'm stuck and can't continue this project as is!!!

答案1

得分: 0

解决方法是在基本的Python 3.4安装上使用pip安装virtualenv,然后通过终端命令手动创建虚拟环境(在Pycharm中可以使用基本Python作为解释器进行操作):

[Python路径]\Python -m venv [Pycharm项目路径]\venv

还要重要的警告:绝对不要在任何时候升级pip到最新版本!在Python 3.4中,这会完全破坏pip,因为最新版本需要Typing模块,而这个模块不是3.4的本机模块。查找适用于3.4的pip的最新支持版本并升级到该版本,不要再往后升级。这将为您节省很多麻烦,哈哈。

(当然,如果可能的话,请尽量在最新版本的Python中工作。不幸的是,如果像我一样需要使用未维护的旧模块,可能无法做到这一点,然后你将不得不应对这些麻烦。)

英文:

After trying a bunch of things, the solution was to pip install virtualenv on the base Python 3.4 install and then manually creating the virtual env by terminal command (doable in Pycharm using the base python as interpreter):

[Python path]\Python -m venv [Pycharm project path]\venv

ALSO IMPORTANT WARNING: Do NOT upgrade pip to the latest version at any point! In Python 3.4 this now completely breaks pip, because the latest version requires the Typing module which is not native to 3.4. Look up what the latest supported version of pip for 3.4 is and upgrade to that and no further. This will save you a bunch of annoyance I had to go through, haha.

(And just obligatory: obviously if at all possible work in the most recent version of Python. Sadly if like me you need to use legacy modules that have not been maintained, this may not be possible and you get to deal with these shenanigans.)

huangapple
  • 本文由 发表于 2023年5月29日 01:57:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76352865.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定