简体   繁体   English

如何使用已经安装的 Python?

[英]How to use an already installed Python?

I have Plex installed on my PC, which relies on Python to run.我的 PC 上安装了 Plex,它依赖 Python 运行。 I know nothing about Python, but I can see that it is running in Windows Task Manager.我对 Python 一无所知,但我可以看到它正在 Windows 任务管理器中运行。 Now, I've got some other unrelated Python scripts that I need to run, but I have no idea how to find where Python is located on my system or how to access it.现在,我还有一些其他不相关的 Python 脚本需要运行,但我不知道如何找到 Python 在我的系统上的位置或如何访问它。

According to How can I find where Python is installed on Windows?根据如何找到 Python 安装在 Windows 上的位置? , I'm supposed to go to my Python interpreter to find out, but I have no idea what or where that is. ,我应该 go 到我的 Python 解释器找出来,但我不知道那是什么或在哪里。

This is completely new to me.这对我来说是全新的。 Could someone hold my hand and walk me through how I can run.py files?有人可以牵着我的手,指导我如何运行.py 文件吗?

Python should be located at C:\Program Files\Python Are you trying to run py files through Command Prompt (CMD) or WindowsPowershell? Python 应位于 C:\Program Files\Python 您是否尝试通过命令提示符 (CMD) 或 WindowsPowershell 运行 py 文件? If yes then you can move to the directory, where your py files are located and just type the name of the py file in your terminal, to run it.如果是,那么您可以移动到 py 文件所在的目录,只需在终端中键入 py 文件的名称即可运行它。

If you still cant find the directory, you can use a python interpreter and write:如果仍然找不到目录,可以使用 python 解释器并编写:

(you can also open python in CMD by typing python then write the code below line by line,hitting enter after each line) (您也可以通过键入 python 在 CMD 中打开python然后逐行编写下面的代码,每行后按回车键)

import os
import sys
print(os.path.dirname(sys.executable))

In Command Prompt(CMD) use cd path_name(f.example desktop) to move in directory, and cd.. to move back.在命令提示符(CMD)中,使用cd path_name(f.example desktop)移入目录,使用cd..移回。 Then you can us dir to see a list of the files in that directory, and simply type the name of your file for example python_file and hit enter to run it.然后,您可以使用dir查看该目录中的文件列表,只需键入文件名,例如python_file并按 Enter 键即可运行它。

(Syntax might differ in WindowsPowershell) (WindowsPowershell 中的语法可能不同)

I will assume you are running on windows,so all you have to do is go to the Window's search option and search Python and you will there is python and then you just have to click it and click on open file location and then you will find the folder of it and your desired python version will be there.Then you just have to left click to go to the properties of it and click on open file location and you will find where you'r python is located and i will assume your python is most likely in the AppData\Local\Programes\Python folder:) I will assume you are running on windows,so all you have to do is go to the Window's search option and search Python and you will there is python and then you just have to click it and click on open file location and then you will find the folder of it and your desired python version will be there.Then you just have to left click to go to the properties of it and click on open file location and you will find where you'r python is located and i will assume your python最有可能在 AppData\Local\Programes\Python 文件夹中:)

In windows: open the command prompt and type python, if it is set in your environment variables (which it asks while installation) it will open the python interpreter.在 windows 中:打开命令提示符并键入 python,如果它在您的环境变量中设置(它在安装时询问),它将打开 python 解释器。

C:\WINDOWS\system32>python
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 22:39:24) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>

for checking other files and modules, try on interpreter below.要检查其他文件和模块,请尝试下面的解释器。

>>> import sys
>>>
>>> print(sys.path)

To execute a python file.执行 python 文件。 Simply open the command prompt and go to the location of the file and type python <name_of_python_file>只需打开命令提示符和 go 到文件的位置,然后键入python <name_of_python_file>

Plex provides their own python libraries. Plex 提供自己的 python 库。 This is built on Python 2.7.这是基于 Python 2.7 构建的。 You do not need Python installed in order to run Plex and it's not recommended to use 2.7 at this point.您不需要安装 Python 即可运行 Plex,此时不建议使用 2.7。 You also cannot use the Python version provided by Plex, in the way you are hoping, as they don't include the executable.您也不能按照您希望的方式使用 Plex 提供的 Python 版本,因为它们不包含可执行文件。

Inside the installation directory of Plex you will see two files.在 Plex 的安装目录中,您将看到两个文件。

  • python27.dll python27.dll
  • python27.zip python27.zip

The contents of the zip folder are very close to the Lib folder from a standard installation of Python 2.7. zip 文件夹的内容非常接近 Python 2.7 标准安装中的Lib文件夹。

None of the provided solutions worked for you because python was not installed or available on your system path.由于python未安装或未在您的系统路径上可用,因此提供的解决方案均不适合您。 Python can be installed by downloading it directly from Python ( https://www.python.org/downloads/ ), executing the downloaded file, and following the prompts. Python can be installed by downloading it directly from Python ( https://www.python.org/downloads/ ), executing the downloaded file, and following the prompts.

An alternative way to install Python is from the Microsoft Store, for Windows.安装 Python 的另一种方法是来自 Microsoft Store,适用于 Windows。

None of the suggestions for finding where Python was installed worked.查找 Python 安装位置的建议均无效。

As @tdelaney mentioned in the comments, even though Plex uses Python and it's running in my system, I don't actually have a standard install of it.正如评论中提到的@tdelaney,即使 Plex 使用 Python 并且它在我的系统中运行,我实际上并没有标准安装它。 I had to go download it.我不得不 go 下载它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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