Win10 安装 Python3 (上)
Python3 For Windows 10
installer
安装







随后可以看到,installer 在用户环境变量PATH中,添加了三项:

卸载
使用 installer 卸载 python 时,并不会移除 launcher。若要移除 launcher,需要打开“程序和功能”,在列表中选择删除。同时,python 也可以通过这里删除或修改。
简单配置
UTF-8 mode
两种方式:
- 设置环境变量 PYTHONUTF8 为 1;
- 在命令行中传递参数
-X utf8
即使该模式未开启,在下面两种情况下,仍将使用 UTF-8:
- Console I/O including standard I/O
- The filesystem encoding
Python Launcher
一个用于选择和执行不同版本 Python 的实用程序。
虚拟环境
如果没有显式给出 Python 版本,且激活了虚拟环境(由标准库 venv 模块或外部的 virtualenv 工具创建),那么 launcher 将使用虚拟环境中的解释器,而非全局的。
文件关联
.py, .pyw, .pyc
只有安装了 launcher,才会产生这些关联。这意味着,我们可以双击执行一个脚本文件,而不用打开命令行。
Shebang Lines
这个东西在 Nix 系统上是原生支持的,而在 Windows 上,由 launcher 来提供这一支持。
虽然很奇怪,但
#!/usr/bin/python
将启用默认的 Python 版本,当然,也可以显式地添加版本后缀,以启用其它版本。
使用 /usr/bin/env 形式的 shebang 将会在 PATH 中搜索 Python 可执行文件,其行为,就如同 Nix 中的 env 程序一样。
此外,也可以在 shebang 中向解释器传递一些选项。
Customization
INI
- 在
%appdata%(当前用户的应用数据目录)中的py.ini;(高优先级) - launcher 所在目录下的
py.ini。
Finding modules
Python 通常将它的库放在安装目录下,默认的库位于 {root}\Lib\,第三方库位于 {root}\Lib\site-packages\。
._pth 和 .pth 文件
pyvenv.cfg 文件
Pip
config
子命令:
- list
- edit
- 需要使用
--editor <editor>指定所用编辑器,否则使用变量 VISUAL 或 EDITOR 指定。 - 很奇怪的是,传入 VScode 的路径,总是报错,而使用 notepad 却没有问题。
- 需要使用
- get
- set
- unset
- debug
作用域选项:
| Options | Descriptions | Locations |
|---|---|---|
| --global | Use the system-wide configuration file only | C:\ProgramData\pip\pip.ini |
| --user | Use the user configuration file only | |
| --site | Use the current environment configuration file only |
file
位置
Per-user
- Default is
%appdata%\pip\pip.ini; - 由于历史原因,
%home%\pip\pip.ini也会被考虑; - 当然,也可以自定一个位置,设置环境变量
PIP_CONFIG_FILE即可。
Inside a virtualenv
%virtual_env%\pip.ini
Global
C:\ProgramData\pip\pip.ini
哪一个
如果发现有多个配置文件,那么按以下顺序进行读取,且后者覆盖前者:
- global
- per-user
- virtualenv-specific
怎么写
The names of the settings are derived from the long command line option, e.g. if you want to use a different package index (--index-url) and set the HTTP timeout (--default-timeout) to 60 seconds your config file would look like this:
[global]
timeout = 60
index-url = https://download.zope.org/ppix
Each subcommand can be configured optionally in its own section so that every global setting with the same name will be overridden; e.g. decreasing the timeout to 10 seconds when running the freeze (pip freeze) command and using 60 seconds for all other commands is possible with:
[global]
timeout = 60
[freeze]
timeout = 10
Boolean options like --ignore-installed or --no-dependencies can be set like this:
[install]
ignore-installed = true
no-dependencies = yes
To enable the boolean options --no-compile, --no-warn-script-location and --no-cache-dir, falsy values have to be used:
[global]
no-cache-dir = false
[install]
no-compile = no
no-warn-script-location = false
For options which can be repeated like --verbose and --quiet, a non-negative integer can be used to represent the level to be specified:
[global]
quiet = 0
verbose = 2
It is possible to append values to a section within a configuration file such as the pip.ini file. This is applicable to appending options like --find-links or --trusted-host, which can be written on multiple lines:
[global]
find-links =
http://download.example.com
[install]
find-links =
http://mirror1.example.com
http://mirror2.example.com
trusted-host =
mirror1.example.com
mirror2.example.com
This enables users to add additional values in the order of entry for such command line arguments.
环境变量
pip’s command line options can be set with environment variables using the format PIP_<UPPER_LONG_NAME> . Dashes (-) have to be replaced with underscores (_).
优先级
命令行参数>环境变量>配置文件
aboutMe
配置了一下镜像源:
> pip config --global set global.index-url https://mirrors.bfsu.edu.cn/pypi/web/simple
这将创建全局配置文件,并写入。
随后我直接在该文件中添加了一些配置项:
[global]
index-url = https://mirrors.bfsu.edu.cn/pypi/web/simple
cache-dir = D:\xxxxx\Documents\Python\pip\cache
注意,虽然看起来 cache-dir 像是和 cache 命令相关的,但实际上它是一个通用选项(General Options),而非 Cache Options,所以,如果将其放在 [cache] 下,将不会产生任何效果。
virtualenv
参考 Virtualenv
Creators
venv
可将创建行为委托给 Python 标准库中的 venv 模块。virtualenv 将创建一个进程来调用该模块,这在 Windows 上将是一笔不小的开销。
builtin
virtualenv 本身便可以执行创建操作。
Seeders
种包指的是 pip,setuptools,wheel 三者中的一或多个。安装种包,将使得你可以在创建的虚拟环境中安装其它的包。对于种包的安装,有两种机制:
pip
使用与 virtualenv 绑定的 pip 安装种包,这将创建一个进程来执行之。
add-data
在用户应用数据目录下创建一个安装镜像,随后要用到时,只需要简单的链接或拷贝这些镜像即可。对 Windows 来说,可能没有使能 symlink,但即便是拷贝,也快得多了。
可以使用环境变量 VIRTUALENV_OVERRIDE_APP_DATA 指定 the seed cache 的位置。
Activators
在虚拟环境目录下,Scripts文件夹中,有一些激活脚本。它们被用来修改 shell 的设置,以确保虚拟环境中的命令要优先于全局路径下的。
CLI interface
virtualenv 主要是一个命令行应用。默认的命令行标志可以被配置文件覆盖,而环境变量又优先于配置。使用 --help 时,可以在帮助信息的最后看到该标志的值,以及是否默认。
| Options | Default | Description |
|---|---|---|
| --app-data | 平台相关(win10 中为 %localappdata%\pypa\virtualenv |
a data folder used as cache by the virtualenv |
| --read-only-app-data | False | 以只读模式使用 app data 文件夹 |
| --reset-app-data | False | 移除 app data 文件夹(即使没有传递必需的 dest) |
| --upgrade-embed-wheels | False | 手动升级内置的 wheels(注意,这个不是特指用于种包的那个 wheel 包) |
| -p, --python | 安装时使用的 python 可执行版本 | 使用哪个 python 可执行文件来创建环境 |
| --creator | builtin if exist, else venv | 用于创建环境的执行者 |
| dest | 要在哪里创建 | |
| --clear | False | 如果目标目录不为空,清除之 |
| --no-vcs-ignore | False | 不要在目标目录下创建 VCS 忽略文件(如 .gitignore |
| --system-site-packages | False | 使得虚拟环境可以访问到全局的 site-packages |
| --symlinks | True | 可以 symlink,就不 copy |
| --copies, --always-copy | False | 总是 copy |
| --seeder | app-data | 种包的安装方式。若选择 pip,则很多选项将无意义 |
| --no-seed, --without-pip | False | 不安装种包 |
| --no-download, --never-download | True | 不要从 PyPI 上下载最新的种包 |
| --download | False | 从 PyPI 上下载最新的种包使用 |
| --pip, --setuptools, --wheel | bundle | 种的版本,默认为与 virtualenv 绑定的那个,否则使用指定的版本(所谓“绑定”,即为“内置”) |
| --no-pip, --no-setuptools, --no-wheel | False | 不安装种包 |
| --no-periodic-update | False | 不对内置的 wheels 进行周期性(14天)更新 |
| --symlink-app-data | False | 从 app data 中符号链接 python 包 |
| --activators | 全部 | 要生成哪些激活器:bash, batch, cshell, fish, powershell, python, xonsh |
| --prompt | (venv_name) | 为该环境指定一个提示符前缀 |
Configuration file
位置
和 pip 一样,virtualenv 也使用标准的 ini 格式的配置文件,默认为 %localappdata%\pypa\virtualenv\virtualenv.ini。
在 --help 输出的最后,可以看到配置文件的位置。可使用 VIRTUALENV_CONFIG_FILE 自定义其位置。
怎么写
基于命令行选项,将左边的 - 符号移除,使用 _ 替换 - 即可配置之。
aboutMe
[virtualenv]
app_data = D:\xxxxx\Documents\Python\pypa\virtualenv
no_vcs_ignore = true
system_site_packages = true
no_periodic_update = true
activators = batch
Misc
- venv — Creation of virtual environments
Note: While symlinks are supported on Windows, they are not recommended. Of particular note is that double-clicking
python.exein File Explorer will resolve the symlink eagerly and ignore the virtual environment.
The created pyvenv.cfg file also includes the include-system-site-packages key, set to true if venv is run with the --system-site-packages option, false otherwise.
When a virtual environment is active, the VIRTUAL_ENV environment variable is set to the path of the virtual environment. This can be used to check if one is running inside a virtual environment.
... However, all scripts installed in a virtual environment should be runnable without activating it, and run with the virtual environment’s Python automatically.
Note: A virtual environment is a Python environment such that the Python interpreter, libraries and scripts installed into it are isolated from those installed in other virtual environments, and (by default) any libraries installed in a “system” Python, i.e., one which is installed as part of your operating system.
A virtual environment is a directory tree which contains Python executable files and other files which indicate that it is a virtual environment.
Common installation tools such as setuptools and pip work as expected with virtual environments. In other words, when a virtual environment is active, they install Python packages into the virtual environment without needing to be told to do so explicitly.
When a virtual environment is active (i.e., the virtual environment’s Python interpreter is running), the attributes
sys.prefixandsys.exec_prefixpoint to the base directory of the virtual environment, whereassys.base_prefixandsys.base_exec_prefixpoint to the non-virtual environment Python installation which was used to create the virtual environment. If a virtual environment is not active, thensys.prefixis the same assys.base_prefixandsys.exec_prefixis the same assys.base_exec_prefix(they all point to a non-virtual environment Python installation).When a virtual environment is active, any options that change the installation path will be ignored from all
distutilsconfiguration files to prevent projects being inadvertently installed outside of the virtual environment.When working in a command shell, users can make a virtual environment active by running an
activatescript in the virtual environment’s executables directory (the precise filename and command to use the file is shell-dependent), which prepends the virtual environment’s directory for executables to thePATHenvironment variable for the running shell. There should be no need in other circumstances to activate a virtual environment; scripts installed into virtual environments have a “shebang” line which points to the virtual environment’s Python interpreter. This means that the script will run with that interpreter regardless of the value ofPATH. On Windows, “shebang” line processing is supported if you have the Python Launcher for Windows installed (this was added to Python in 3.3 - see PEP 397 for more details). Thus, double-clicking an installed script in a Windows Explorer window should run the script with the correct interpreter without there needing to be any reference to its virtual environment inPATH.
Win10 安装 Python3 (上)的更多相关文章
- WIN10安装不上IIS,使用IISExpress作为发布服务
[背景] 本人开发Win程序,需要调用网站资源作为Win程序的辅助功能,为此需要本地开发环境支持IIS.最近重装系统,VS安装完后,接着再安装IIS,可以在添加删除程序中反复尝试,均告安装失败提示.最 ...
- 【转】Win10下python3和python2多版本同时安装并解决pip共存问题
[转]Win10下python3和python2多版本同时安装并解决pip共存问题 特别说明,本文是在Windows64位系统下进行的,32位系统请下载相应版本的安装包,安装方法类似. 使用pytho ...
- Win10 安装 Anaconda3 用 Anaconda3 安装TensorFlow 1.2 (只支持python3.5)
Win10 安装 Anaconda3 1.安装Anaconda3 选择相应的Anaconda进行安装,下载地址点击这里,下载对应系统版本的Anaconda,官网现在的版本是Anaconda 4.3.1 ...
- python环境搭建-在Windows上安装python3.5.2
在Windows上安装Python3.5.2 首先,根据你的Windows版本(64位还是32位)从Python的官方网站下载Python 3.5.2对应的64位安装程序或32位安装程序(网速慢的同学 ...
- 在Linux上安装Python3
1. 安装依赖环境 # yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline- ...
- 在CentOS上安装Python3的三种方法
Centos7默认自带了Python2.7版本,但是因为项目需要使用Python3.x你可以按照此文的三个方法进行安装. 注:本文示例安装版本为Python3.5, 一.Python源代码编译安装 安 ...
- centos7.4上安装python3环境的坑
前言:为了将爬虫项目布置到服务器上,才有了今天这一下午的坑,必须记录 不要动现有的python2环境!不要动现有的python2环境!不要动现有的python2环境! 解压 tar -xvf Pyth ...
- 如何在CentOS7上安装Python3及对应问题
首先一般来说安装好的CentOS是会自带python2.7,但是是没有安装python3的环境的 [root@host bin]# pwd /usr/bin [root@host bin]# ls p ...
- 解决在Mac上用pyenv安装python3失败的问题
背景 前段时间在本地Mac系统上要跑一个python3写的压测脚本. Mac默认安装的是python2, 而且很多软件依赖的也是python2. 为了不影响现有系统其它软件, 当时安装了pyenv来实 ...
随机推荐
- 浅谈 C# Assembly 与 IL (一):C# Assembly 与 Reflection
作者:Compasslg 前言 前一阵子想利用闲余时间写一个 Unity 游戏的翻译工具,主要是用于翻译一些内嵌在代码中的文本,最初想偷懒看了一下网上的教学推荐说可以先利用DnSpy.ILSpy等工具 ...
- k8s cronjob
k8s cronjob 只存在于v1beta1中 可以周期性 定时执行任务, 事例 [root@master01 ~]# kubectl apply -f mycronjob-busybox.yaml ...
- web前端的超神之路
前端超神之路 前端基础知识 HTML :用户实现页面的工具 CSS:用于美化界面的工具 javascript:用于操作html元素和css样式,让你的页面效果更美观 前端进阶知识 jQuery:用于简 ...
- Java 基础 一文搞懂泛型
本文将从以下四个方面来系统的讲解一下泛型,基本上涵盖了泛型的主体内容. 什么是泛型? 为什么要使用泛型? 如何使用泛型? 泛型的特性 1. 什么是泛型? 泛型的英文是Generics,是指在定义方法. ...
- 案例分析——Who is the king of handwriting notes?
案例分析--Who is the king of handwriting notes? 项目 内容 这个作业属于那个课程 2021春季学期软件工程(罗杰.任健) 这个作业的要求在哪里 案例分析 我在这 ...
- Josephus问题的queue解法
问题描述 Josephus问题是一个非常古老的问题.它的范型描述为N个人(0到N-1)围成一圈报数,报道M的人会被剔除,直到最后一个人. 要求找出最后一个人的位置或这N个人被剔除的顺序. 解决思路 我 ...
- 【布隆过滤器】基于Hutool库实现的布隆过滤器Demo
布隆过滤器出现的背景: 如果想判断一个元素是不是在一个集合里,一般想到的是将集合中所有元素保存起来,然后通过比较确定.链表.树.散列表(又叫哈希表,Hash table)等等数据结构都是这种思路,存储 ...
- 【转】【linux系统】nacos + confd配置nginx
为什么要支持confd,老的应用配置管理模式是启动时读取配置文件,然后重新读取配置文件需要应用重启.一般的配置管理系统都是代码侵入性的,应用接入配置管理系统都需要使用对应的SDK来查询和监听数据的变更 ...
- Linux中Nginx服务器的部署和配置
目录 Nginx安装方式: yum源安装 目录结构: 源码包安装 目录结构: Nginx中支持PHP Nginx中配置php对mysql数据库的支持 Nginx配置反向代理服务器 正常代理 根据不同端 ...
- 缓冲区溢出之栈溢出利用(手动编写无 payload 的 Exploit)
0x01 介绍 Exploit 的英文意思就是利用,它在黑客眼里就是漏洞利用.有漏洞不一定就有Exploit(利用),有Exploit就肯定有漏洞.编写缓冲区溢出的Exploit分为3个方面:漏洞溢出 ...