Pycharm virtual env error

Hi everyone, this is my first post in the forum. :sweat_smile:

I’m having some issues with PyCharm, and as a beginner, I’m struggling to understand the error that occurs when I try to create a new virtual environment.

Initially, I started my project using Python 3.0, but I noticed that the autocomplete frequently showed errors due to IronPython 2.7 syntax. As a result, I decided to install Python 2.7 and uninstall Python 3.0.

However, when I tried to create a new virtual environment from scratch, I encountered the following error:

Traceback (most recent call last):
  File "C:\Python27\lib\runpy.py", line 165, in _run_module_as_main
    mod_name, loader, code, fname = _get_main_module_details(_Error)
  File "C:\Python27\lib\runpy.py", line 133, in _get_main_module_details
    return _get_module_details(main_name)
  File "C:\Python27\lib\runpy.py", line 119, in _get_module_details
    code = loader.get_code(mod_name)
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2024.3.1.1\plugins\python-ce\helpers\virtualenv-20.24.5.pyz\__main__.py", line 13
    def __init__(self) -> None:
                              ^
SyntaxError: invalid syntax

My Environment:

Microsoft Windows 10 [Version 10.0.26100]
Latest Installed .Net Framework: 8.0.0
No .Net Target Packs are installed.
No .Net-Core Target Packs are installed.
pyRevit CLI v5.0.0.24345+0715-wip.9828ebd2ffcd6080ff943974b63b673ce38f1889

I’ve asked for help in other forums, but most people recommend using Python 3.0. Unfortunately, as we know, pyRevit is based on IronPython 2.7.

I’m stuck and it’s driving me crazy. I hope someone here can help me figure this out.

Cheers!

Hi @AntonioRojas01, welcome to the forum!

The problem is that pycharm is trying to use its own virtualenv package, which is written for python 3.

You have to create the virtualenv by yourself outside pycharm, then add it to pycharm using the “existing envitonment”.
But if you use python 2.7 only for pyrevit, you can skip the virtualenv and directly add the path of the python executable you just installed

1 Like

That’s it. yeah¡¡
Thank you.

This guides me to study about virtual environments.

And for those who maybe are stuck with this like me, here is a video explaning virtual envs