python安装笔记_python安装笔记

python setup.py build

python setup.py install

1. build

python setup.py build

the build command is responsible for putting the files to install into a build directory.

change the build dir:

python setup.py build --build-base=/path/to/pybuild/foo-1.0

2. install

python setup.py install

the install command is relatively simple: copy everything under build/lib (or build/lib.plat ) to your chosen installation directory.

2.1 alternate installation

The basic idea is that you supply a base directory for the installation, and the install command picks a set of directories (called an installation scheme) under this base directory in which to install files.

--user

--home

--prefix

--exec-prefix

--install-base

--install-platbase

2.1.1 alternate installation - the user scheme

When don’t have write permission to the global site-packages directory or don’t want to install into it:

python setup.py install --user

Type of file

Installation directory

modules

userbase/lib/pythonX.Y/site-packages

scripts

userbase/bin

data

userbase

C headers

userbase/include/pythonX.Y/distname

2.1.2 Alternate installation: the home scheme

when you build and maintain a personal stash of Python modules. just like Unix's "home" dir.

e.g. python setup.py install --home=~

Type of file

Installation directory

modules

home/lib/python

scripts

home/bin

data

home

C headers

home/include/python/distname

2.1.3 Alternate installation: Unix (the prefix scheme)

when you wish to use one Python installation to perform the build/install (i.e., to run the setup script), but install modules into the third-party module directory of a different Python installation (or something that looks like a different Python installation).

e.g. /usr/local/bin/python setup.py install --prefix=/mnt/@server/export

Type of file

Installation directory

Python modules

prefix/lib/pythonX.Y/site-packages

extension modules

exec-prefix/lib/pythonX.Y/site-packages

scripts

prefix/bin

data

prefix

C headers

prefix/include/pythonX.Y/distname

every time you run python setup.py install without any other options, you’re using --prefix and --exec-prefix.

2.2 Custom installation

Type of file

Override option

Python modules

--install-purelib

extension modules

--install-platlib

all modules

--install-lib

scripts

--install-scripts

data

--install-data

C headers

--install-headers

python setup.py install --home=~/python \

--install-purelib=lib \

--install-platlib='lib.$PLAT' \

--install-scripts=scripts

--install-data=data

or use Distutils config file (see section Distutils Configuration Files):

[install]

install-base=$HOME/python

install-purelib=lib

install-platlib=lib.$PLAT

install-scripts=scripts

install-data=data

2.2.1 Modifying Python’s Search Path

When the Python interpreter executes an import statement, it searches for both Python code and extension modules along a search path. A default value for the path is configured into the Python binary when the interpreter is built. You can determine the path by importing the sysmodule and printing the value of sys.path.

The most convenient way is to add a path configuration file to a directory that’s already on Python’s path, usually to the .../site-packages/ directory. Path configuration files have an extension of .pth, and each line must contain a single path that will be appended to sys.path. (Because the new paths are appended to sys.path, modules in the added directories will not override standard modules. This means you can’t use this mechanism for installing fixed versions of standard modules.)

import sys

sys.path.append('/www/python/')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,让我来回答你的问题。以下是一个使用 Tkinter 和 FileDialog 实现打开和保存文件的示例程序: ```python import tkinter as tk from tkinter import filedialog class App(tk.Frame): def __init__(self, master=None): super().__init__(master) self.master = master self.pack() self.create_widgets() def create_widgets(self): self.text = tk.Text(self) self.text.pack() self.open_button = tk.Button(self, text="打开文件", command=self.open_file) self.open_button.pack(side="left") self.save_button = tk.Button(self, text="保存文件", command=self.save_file) self.save_button.pack(side="left") def open_file(self): file_path = filedialog.askopenfilename() if file_path: with open(file_path, "r") as file: file_content = file.read() self.text.delete("1.0", tk.END) self.text.insert(tk.END, file_content) def save_file(self): file_path = filedialog.asksaveasfilename(defaultextension=".txt") if file_path: with open(file_path, "w") as file: file_content = self.text.get("1.0", tk.END) file.write(file_content) root = tk.Tk() app = App(master=root) app.mainloop() ``` 这个程序创建了一个简单的文本编辑器,包含打开文件和保存文件的按钮。当用户点击“打开文件”按钮时,程序会弹出一个文件对话框,用户可以选择要打开的文件。当用户点击“保存文件”按钮时,程序会弹出一个文件对话框,用户可以选择保存文件的路径和文件名。程序会将用户输入的内容保存到文件中。 希望这个示例对你有帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值