3

I just struggled with an error message of "This SDK seems invalid" when trying to use a Python virtual environment that I copied from a customer's machine and which I originally installed on his machine. The problem ended up being that the Python folder in the "home" setting in pyenv.cfg was the folder on the customer's machine, not the one on my machine. Once I fixed that, it worked.

But I am confused (yet again) by how virtual environments work. I was led to the solution by this thread, which says that while virtual environments isolate libraries and settings, they don't isolate the Python installation itself. But if that's the case, why is there a python.exe file in my venv folder? Or does the home setting usually point to the file in the venv folder, and it got changed somehow on my customer's machine?

ROBERT RICHARDSON
  • 2,077
  • 4
  • 24
  • 57
  • can you elaborate more, what you are trying to do and achieve, i suggest you to try to setup virtual env through command line than using pycharm default IDE this will help you more to understand – sahasrara62 Oct 13 '20 at 14:04
  • No, I'm afraid I can't elaborate more. At this point, I know how to do what I need to do. what I am trying to achieve is an understanding of why I had to do it. More specifically, I want to know why a virtual environment needs a reference to an outside installation of Python when the venv itself contains an installation of Python. – ROBERT RICHARDSON Oct 13 '20 at 14:11
  • to create a virtual env using pipenv for example you need a `pipenv` python module and `pip` module and there dependecies, to run these we need python local installation or module ( you need to specify path than in bashrc file) these file will fetch/download the new python setup according to the version specified and files then it create the virtual environment. – sahasrara62 Oct 13 '20 at 15:09
  • Thank you, but that does not answer my question. Why is there a setting in pyenv.cfg pointing to a Python installation outside the venv, when there is a a Python installation inside the venv? When the venv is created, we obviously need to know what Python installation to base it off of, but I don't understand why we need to know about any outside Python installations after the venv is created. – ROBERT RICHARDSON Oct 13 '20 at 15:22
  • i am sorry i am not able to much help, but @sinoroc provide PEP 405 In solution, might be reason for this. this one really new to me and thanks for increasing my knowledge – sahasrara62 Oct 13 '20 at 17:09
  • @ROBERTRICHARDSON at least under macos and Linux, the python exe is a symlink, not an actual file at that location. No idea under Windows, symlinks are available since 7, but very underutilized. Also, venv are not *necessarily* as stand-alone as you think - they *can* be configured to use system-level pip packages for example. – JL Peyret Oct 13 '20 at 18:06

1 Answers1

0

I can not claim to know the exact answer to this. My guess is that home is needed to find things such as the standard library, etc. Those are not copied for each virtual environment. You may want to read PEP 405 to find out the details.

sinoroc
  • 18,409
  • 2
  • 39
  • 70