0

My colleague has upgraded Python from 3.10 to 3.12 on a server via unzipping the file "Windows embeddable package (64-bit)" downloaded at https://www.python.org/downloads/windows/ into the folder python310. Now I found that quit() does not quit python when python is started in a CMD window. The error message reads as below:

        Traceback (most recent all last):
        File "<stdin>", line 1, in <module>
        NameError: name 'quit' is not defined.

How to solve this problem? Can still other problem occur? Is this kind of upgrade correct anyway? Many thanks in advance for any hints! Weichao Wang

6
  • What command line options is your colleague using to start Python? If -S is included, then the site module won't be automatically imported at startup, and exit/quit won't be defined. Commented Nov 2, 2023 at 15:58
  • 1
    "My colleague has upgraded Python from 3.10 to 3.12 on a server via unzipping the file "Windows embeddable package (64-bit)" downloaded at python.org/downloads/windows into the folder python310" oh that is definitely very wrong. Don't do that. Both compiled CPython bytecode and C modules are interpreter-specific. You can just insert Python 3.12 interpreter files directly into a Python 3.10 installation and expect anything to work. Commented Nov 2, 2023 at 16:01
  • 1
    It sounds very likely that your colleague has hopelessly corrupted the Python installation on the server. The old installation path is now a conglomerate of incompatible files for two different programs. It will most likely need to be deleted and re-installed from scratch. Commented Nov 2, 2023 at 16:04
  • Maybe you mean "You can not just insert Python 3.12 interpreter files directly into a Python 3.10 installation and expect anything to work."? How to delete the old version? Just remove the folder "Python" from the Harddisk? If various packages are installed, for example, pyautogui, pandas, can they still be used after having removed the old Python version and installed the new one? Commented Nov 3, 2023 at 9:19
  • Yes, that is what I meant :) You can uninstall the old interpreter as you would any other program. Deleting the folder should work, but there may (?) be some artifacts left behind in other locations. Any packages there were installed for the old interpreter will need to be re-installed Commented Nov 3, 2023 at 13:46

1 Answer 1

1

If you check python documentation on the embeddable package it says

The embedded distribution is a ZIP file containing a minimal Python environment. It is intended for acting as part of another application, rather than being directly accessed by end-users.

There are two ways to solve this.

  • Modifying python*._pth file: This file should be included when you unzipped the embeddable package (python312._pth). This file in python can modify the search path for the modules. The file will have commented the line import site, this module is the one that imports the quit() command. Uncomment it and it should look like this:

     python312.zip
     .
    
     # Uncomment to run site.main() automatically
     import site
    
  • Manually importing site module: The quit() command is in the module site. So you can execute this commands in the interactive mode for it to work:

      >>> import site
      >>> site.main() # Adds all the standard site-specific directories to the module search path
      >>> quit() # Now quit() can be used without error
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.