0

TL;DR - Microsoft Store Apps are broken (0 bytes), hence the Python interpreter is unable to create process and run "Python" inside virtualenv, I failed to follow numerous explanations of how to change virtualenv path for Python.

Recently, without any changes to my computer/environment, an issue started occurring when executing (also tried python3, which brings the same):

python manage.py runserver

This brought back the following issue:

Unable to create process using '"C:\Users\MyUser\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\python.exe"'

As I dug deeper, I realized that all of the apps installed under this folder are 0 bytes, hence they are completed broken, all of a sudden. Therefore I figured it's not an issue with Django, rather the python itself.

I tried changing the virtualenv path for Python.exe, instead of using WindowsApps version, I installed the original Python from the original website.

I failed to do so, multiple times.

I tried: "https://stackoverflow.com/questions/4757178/how-do-you-set-your-pythonpath-in-an-already-created-virtualenv/47184788#47184788" - Adding the path inside "activate" and "activate.bat", as

set PYTHONPATH="C:\Users\MyUser\AppData\Local\Programs\Python\Python310\python.exe"

And the issue persists.

I tried every solution/article I found in regards to the issue I have. Many of them claim a simple result, whereas the rest claim a complete refactor is required. Even downloading from Microsoft store is broken, it always fails.

Since I'm unable to remove the broken apps, and I wasn't able to find a way to change the virtualenv Python interpreter, I am here, asking for your assistance.

Thanks in advance,

Spytolie
  • 1
  • 4
  • 1
    It's usually a lot easier to rebuild your virtual environment than to try to fix it. Are all of your dependencies declared, e.g. in a `requirements.txt` (for pip), `pyproject.toml` (for Poetry), or `Pipfile` (for Pipenv)? – ChrisGPT was on strike Oct 23 '22 at 12:43

2 Answers2

0

Since you have installed python from python.org, ensure that it has been properly added to the PATH and you're not inadvertently using the windows store version.

  1. Open command prompt
  2. Execute where python to check which python your system is using.

where python example

If you're only seeing the WindowsApps version of python listed in the output of where command, then python installer apparently didn't add the location to PATH, so you'll need to manually add it yourself.

Also, if you're not restricted to use virtualenv, you can give conda a try.

zyrif
  • 32
  • 1
  • 5
  • Thanks for your response. I do see the recently-installed python 3.10 in the PATH. The WindowsApps version is (apparently) attached to the virtualenv of the Django project I have. And it still won't work... In regards to Conda, I'll try giving it a shot, if there's an easy way to convert projects – Spytolie Oct 23 '22 at 12:30
  • Why are you referencing Anaconda when OP is using Python from `python.org` (which you explicitly state in your answer)? @Spytolie, there is absolutely _no need_ to switch to Anaconda. – ChrisGPT was on strike Oct 23 '22 at 12:41
  • @Spytolie You can try creating a `requirements.txt` file manually and add only the necessary dependencies for your project there (e.g django, psycopg2). Then you can do `pip install -r requirements.txt` and pip will automatically install any additional dependencies. Also, in your original question, I believe you're trying to use `PYTHONPATH` incorrectly. The purpose of `PYTHONPATH` isn't to point to python binary, it's used by python itself to look for modules. More info: https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH – zyrif Oct 23 '22 at 12:47
  • Hello @Zyrif, just to make sure I understood correctly, this suggestion refers to a complete re-build of the virtual environment, just with the correct Python path, is that correct? – Spytolie Oct 23 '22 at 14:48
  • @Spytolie Yes, since that is the least convoluted way to use a different python interpreter than the one used to create it, and to re-create the environment, you need a working system python, hence my answer. Also, When you create an environment using virtualenv, the python interpreter (python.exe) is **_copied_**, not symlinked. So it's more like the correct python interpreter _copy_, rather than the correct interpreter _path_. When you create the virtual environment using the python.org distribution, it'll automatically include the python.org version of the interpreter. – zyrif Oct 23 '22 at 21:49
0

As I began rebuilding, I figured it out.

When building a virtualenv, the python I used was directing to:

"C:\Users\MyUser\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\python.exe"'

Python interpreter is saved as the "PATH" to execute python. Since my Python interpreter from Microsoft Store went broke, I was unable to execute python inside the virtual environment.

  • Venv configures a file called:

pyvenv.cfg

This is how the virtual environment knows what Python interpreter to use. Inside it, the first line states:

home = C:\Users\MyUser\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\

Therefore, we just need to re-configure it to the new path of Python interpreter:

home = C:\Users\MyUser\AppData\Local\Programs\Python\Python310

And it worked for me.

Thanks for everyone's assistant, glad it's done.

Spytolie
  • 1
  • 4