Why I Didn't Install Python from the Microsoft Store
Tags: windows, python, todayilearned
Published: 2020-11-05 00:53:36

I am a big Python fan! So, please do not stop me from installing Python on Windows. As far as I know, we have two ways of doing it. The first option is we can download the installer from [the official page](https://www.python.org/downloads/) which I believe this is the solution preferred by the most users.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/bcoxp5fb3qn86sdwz5vb.png)

But come on, I do not want to bother Microsoft Defender SmartScreen! So, I went to the second option which is to download it from Microsoft Store! Love it! This is the easiest way to take it home! Please note that there are actually a few other options, but I am just too lazy to say it all.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/pevwmsbrna7xs907br3d.png)

After the installation has finished, I went to the Windows Terminal, typed in `python` and hit enter/return key within a second or two. Suddenly, I got a horror error message screaming at me in red.

```powershell
> python
python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ python
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (python:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

> where.exe python
INFO: Could not find files for the given pattern(s).
```

Then I checked my user path variables and I found nothing but a single entry sitting there for an unknown amount of time.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/gor4ngm4lhs26beudgln.png)

No Python! But since it is the path for all applications installed from the Microsoft Store, I took the initiative to go to `C:\Users\Naufan Rusyda Faikar\AppData\Local\Microsoft\WindowsApps` using File Explorer.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/iimm7ugu4vv6rov0ogyv.png)

From there, I had found that it have to be `python3.9` with the specific version as a suffix. Alright, I had no problem with that.

```powershell
> where.exe python3.9
C:\Users\Naufan Rusyda Faikar\AppData\Local\Microsoft\WindowsApps\python3.9.exe

> where.exe pip
C:\Users\Naufan Rusyda Faikar\AppData\Local\Microsoft\WindowsApps\pip.exe
```

Before installing some packages, I used to upgrade `pip`. Inspite of my success, a warning had plagued the day.

```powershell
> python3.9 -m pip install --upgrade pip
Collecting pip
  Downloading pip-20.2.4-py2.py3-none-any.whl (1.5 MB)
     |████████████████████████████████| 1.5 MB 525 kB/s
Installing collected packages: pip
  WARNING: The scripts pip.exe, pip3.9.exe and pip3.exe are installed in 'C:\Users\Naufan Rusyda Faikar\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-20.2.4
```

Do you realize where the inconsistency lies? Let me make it clearer.

```powershell
> where.exe pip
C:\Users\Naufan Rusyda Faikar\AppData\Local\Microsoft\WindowsApps\pip.exe

> pip --version
pip 20.2.4 from C:\Users\Naufan Rusyda Faikar\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pip (python 3.9)
```

The `where.exe` command had no knowledge of where the "usable" `pip` command is. Even if I did get more specific.

```powershell
> where.exe python3.9
C:\Users\Naufan Rusyda Faikar\AppData\Local\Microsoft\WindowsApps\python3.9.exe

> python3.9 -m pip --version
pip 20.2.4 from C:\Users\Naufan Rusyda Faikar\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pip (python 3.9)

> & 'C:\Users\Naufan Rusyda Faikar\AppData\Local\Microsoft\WindowsApps\pip.exe' --version
pip 20.2.4 from C:\Users\Naufan Rusyda Faikar\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pip (python 3.9)
```

Then I just realized that somehow all the files under `C:\Users\Naufan Rusyda Faikar\AppData\Local\Microsoft\WindowsApps` are "shortcuts" to the actual executable. I do not care anymore because I got the latest version of `pip`!

Next, I wanted to create a virtual environment for testing.

```powershell
> pip install virtualenv
...

> virtualenv venv
virtualenv : The term 'virtualenv' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ virtualenv venv
+ ~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (virtualenv:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
```

Wait, how come! It had been confusing me. The package went into somewhere which in my case went into `%USERPROFILE%\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts`. Okay, let's go another way.

```powershell
> python3.9 -m virtualenv venv
RuntimeError: failed to build image pip because:
Traceback (most recent call last):
  File "C:\Users\Naufan Rusyda Faikar\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\virtualenv\seed\embed\via_app_data\via_app_data.py", line 57, in _install
    installer.build_image()
  File "C:\Users\Naufan Rusyda Faikar\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\virtualenv\seed\embed\via_app_data\pip_install\base.py", line 54, in build_image
    zip_ref.extractall(str(self._image_dir))
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.240.0_x64__qbz5n2kfra8p0\lib\zipfile.py", line 1633, in extractall
    self._extract_member(zipinfo, path, pwd)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.240.0_x64__qbz5n2kfra8p0\lib\zipfile.py", line 1687, in _extract_member
    open(targetpath, "wb") as target:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Naufan Rusyda Faikar\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\Local\\pypa\\virtualenv\\wheel\\3.9\\image\\1\\CopyPipInstall\\pip-20.2.4-py2.py3-none-any\\pip\\_vendor\\urllib3\\packages\\ssl_match_hostname\\_implementation.py'
```

Huh!? Microsoft is making things complicated! I have read from [a GitHub issue page](https://github.com/pypa/virtualenv/issues/1971) that I had most likely just reached the Windows long path limit.  But I had to stop here, so that this post will not be too long in resentment.

> Please note, if you want to install Python on Windows, I would recommend to go with the first option. As you can see in the attachment below, the installer gives you the option to disable the path length limit.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/fd1aj31bn0e0xlshsi9b.png)

Actually, it will run a similar command in PowerShell as below.

```powershell
> & 'C:\Users\Naufan Rusyda Faikar\AppData\Local\Programs\Python\Python39\pythonw.exe' -c "import winreg; winreg.SetValueEx(winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, r'SYSTEM\CurrentControlSet\Control\FileSystem'), 'LongPathsEnabled', None, winreg.REG_DWORD, 1)"
```

You can read from [the official website](https://docs.python.org/3/using/windows.html#the-microsoft-store-package) on this specific issue. I hope you get the idea. Thanks for reading!