简体   繁体   中英

Running a simple local HTTP server using Python 3.x

I'm following this help page: https://developer.mozilla.org/en-US/docs/Learn/Common_questions/set_up_a_local_testing_server

I'm running Windows 10 and Python 3.7.8. I created a folder where I want a test environment. Then I changed the directory in the command prompt to that folder and ran the command to start up the server. C:\Users\jpilbeam\TestEnvironment>python3 -m http.server

But that did not work, and neither did the alternative port 7800: Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases. Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.

I know I have a couple copies of Python 3.x on my machine. From the terminal I only found one using this: python -c "import sys; print('\n'.join(sys.path))"

Prints: C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64

Based on that help doc, I'm not able to set up the server.

Make sure python is added to your environment paths. If you are not sure how to do this you can follow this or uninstall and reinstall Python and make sure to tick the box where it says add to environment paths.

Try doing python --version and if it comes up your environment path has been set.

Try using python -m http.server instead.

Thanks to FluxedScript, I did the following workflow to get it to work: (1) Windows start menu --> typed in environment variables (2) In System Properties menu I clicked Environment Variables (3) In the System variables window of the Environment Variables menu I highlighted Path and clicked Edit (4) I clicked New then entered: C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64 ---> then clicked OK on all menus

Back in the command prompt:

C:\Users\jpilbeam>cd C:\Users\jpilbeam\TestEnvironment

C:\Users\jpilbeam\TestEnvironment>py -V
Python 3.7.8

C:\Users\jpilbeam\TestEnvironment>python3 -m http.server ###this did not work!

C:\Users\jpilbeam\TestEnvironment>python -m http.server ###this did work!
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM