2

Recently, I tried to install pypoetry on my windows. The python I used was installed from MS store. And I found something strange.

C:\Users\Liu.D.H>where python
C:\Users\Liu.D.H\AppData\Local\Microsoft\WindowsApps\python.exe
C:\Users\Liu.D.H\anaconda3\python.exe

C:\Users\Liu.D.H>C:\Users\Liu.D.H\anaconda3\python.exe
Python 3.8.8 (default, Apr 13 2021, 15:08:03) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32

Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated.  Libraries may fail to load.  To activate this environment
please see https://conda.io/activation

Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path.realpath("C:/Users/Liu.D.H/AppData/Roaming/pypoetry")
'C:\\Users\\Liu.D.H\\AppData\\Roaming\\pypoetry'
>>> exit()

C:\Users\Liu.D.H>python
Python 3.10.1 (tags/v3.10.1:2cd268a, Dec  6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path.realpath("C:/Users/Liu.D.H/AppData/Roaming/pypoetry")
'C:\\Users\\Liu.D.H\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\LocalCache\\Roaming\\pypoetry'
>>> exit()

C:\Users\Liu.D.H>

I also tried the realpath of node.

C:\Users\Liu.D.H>node
Welcome to Node.js v14.18.1.
Type ".help" for more information.
> fs.realpathSync("C:/Users/Liu.D.H/AppData/Roaming/pypoetry")
Uncaught:
Error: ENOENT: no such file or directory, lstat 'C:\Users\Liu.D.H\AppData\Roaming\pypoetry'
    at Object.realpathSync (fs.js:1800:7) {
  errno: -4058,
  syscall: 'lstat',
  code: 'ENOENT',
  path: 'C:\\Users\\Liu.D.H\\AppData\\Roaming\\pypoetry'
}
>

So, the %APPDATA%/sub_path location in windows is process-dependent?

Donghua Liu
  • 1,776
  • 2
  • 21
  • 30
  • Python's realpath does not care if the path does not exist. Even for a path that does not exist, it just returns the resolved path. Apparently node.js does care? – Kota Mori Dec 10 '21 at 07:34
  • @KotaMori Thanks, however my problem is the result of `os.path.realpath("C:/Users/Liu.D.H/AppData/Roaming/pypoetry")` in different python is different, and why? – Donghua Liu Dec 10 '21 at 07:48
  • 1
    Thats indeed witchcraft! Gotta check source code after doing some task. Mind if I suggest splitting python3.8.8 output and 3.10 output in different code block? I almost missed there were 2 independent python runs. – jupiterbjy Dec 10 '21 at 07:58
  • In one case there is the warning "This Python interpreter is in a conda environment, but the environment has not been activated.". What happens if you activate the environment? Does the output still differ? – Matthias Dec 10 '21 at 08:22
  • The root magic is if `"C:\Users\Liu.D.H\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\Roaming\pypoetry"` is exists, then `os.path.realpath("C:/Users/Liu.D.H/AppData/Roaming/pypoetry")` return the this magic path, if `C:\Users\Liu.D.H\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\Roaming\pypoetry2` is not exist, then `os.path.realpath("C:/Users/Liu.D.H/AppData/Roaming/pypoetry2")` return the same `"C:/Users/Liu.D.H/AppData/Roaming/pypoetry2"` – Donghua Liu Dec 10 '21 at 09:19
  • I found the actual function called in realpath is _getfinalpathname which is in nt module, the source code is in C on https://github.com/python/cpython/blob/4325a766f5f603ef6dfb8c4d5798e5e73cb5efd5/Modules/posixmodule.c#L4271-L4347. – Donghua Liu Dec 12 '21 at 08:25

0 Answers0