sys.path will use user site-packages over the environment's site-packages
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- python
- 领域
- build-system
调研方向
使用 issue 中所示的 user-site 设置和命令,分别在 root 和全新的 conda 环境中检查 sys.path,以复现所报告的行为。阅读 PEP 370 和 Python site-path 初始化入口;完成的标准是环境的 site-packages 没有被 user site-packages 意外遮蔽。
由索引模型根据 Issue 内容生成。
描述
Hello,
I'm following up on a recommendation from @jakirkham in the R-base feedstock in this issue:
https://github.com/conda-forge/r-base-feedstock/issues/37 where we see similar behavior in R with respect to .libPaths().
According to PEP 370 there are platform-specific paths in which users can install packages which will be included in sys.path. The unfortunate result is that if you have a package installed there, it may be incompatible with a given conda environment's binaries and cause issues. Worse, the user-package is always preferred in import-order, so this will impact every environment (including root).
I'm kind of torn as to whether this is or is not a bug, but I'm reporting it in any case for further discussion.
Here is a demonstration showing this in a root environment from defaults and a conda-forge environment using the Python from this feedstock.
boring conda-info for completeness
16:33:55 ~
§ conda info
active environment : None
user config file : /home/evan/.condarc
populated config files :
conda version : 4.4.11
conda-build version : 3.0.28
python version : 3.6.1.final.0
base environment : /opt/Miniconda3 (read only)
channel URLs : https://repo.continuum.io/pkgs/main/linux-64
https://repo.continuum.io/pkgs/main/noarch
https://repo.continuum.io/pkgs/free/linux-64
https://repo.continuum.io/pkgs/free/noarch
https://repo.continuum.io/pkgs/r/linux-64
https://repo.continuum.io/pkgs/r/noarch
https://repo.continuum.io/pkgs/pro/linux-64
https://repo.continuum.io/pkgs/pro/noarch
package cache : /opt/Miniconda3/pkgs
/home/evan/.conda/pkgs
envs directories : /home/evan/.conda/envs
/opt/Miniconda3/envs
platform : linux-64
user-agent : conda/4.4.11 requests/2.14.2 CPython/3.6.1 Linux/4.15.7-1-ARCH arch/ glibc/2.26
UID:GID : 1000:100
netrc file : None
offline mode : False
Set up the user-site packages and add a Hello World package:
16:33:59 ~
§ mkdir -p ~/.local/lib/python3.6/site-packages
16:34:07 ~
§ echo "print('Hello World')" > ~/.local/lib/python3.6/site-packages/hello.py
Try it in the root environment:
16:34:13 ~
§ which python
/opt/Miniconda3/bin/python
16:34:20 ~
§ python
Python 3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 13:09:58)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/opt/Miniconda3/lib/python36.zip', '/opt/Miniconda3/lib/python3.6', '/opt/Miniconda3/lib/python3.6/lib-dynload', '/home/evan/.local/lib/python3.6/site-packages', '/opt/Miniconda3/lib/python3.6/site-packages']
>>>
>>> import hello
Hello World
>>>
Note the end of sys.path: '/home/evan/.local/lib/python3.6/site-packages', '/opt/Miniconda3/lib/python3.6/site-packages'] the .local site-packages takes precedence over the environment's.
Try it in a fresh conda-forge environment:
16:34:40 ~
§ conda create -n example -c conda-forge python=3.6
Boring output of install plan
Solving environment: done
## Package Plan ##
environment location: /home/evan/.conda/envs/example
added / updated specs:
- python=3.6
The following packages will be downloaded:
package | build
---------------------------|-----------------
certifi-2018.1.18 | py36_0 143 KB conda-forge
setuptools-38.5.2 | py36_0 525 KB conda-forge
------------------------------------------------------------
Total: 668 KB
The following NEW packages will be INSTALLED:
ca-certificates: 2018.1.18-0 conda-forge
certifi: 2018.1.18-py36_0 conda-forge
ncurses: 5.9-10 conda-forge
openssl: 1.0.2n-0 conda-forge
pip: 9.0.1-py36_1 conda-forge
python: 3.6.4-0 conda-forge
readline: 7.0-0 conda-forge
setuptools: 38.5.2-py36_0 conda-forge
sqlite: 3.20.1-2 conda-forge
tk: 8.6.7-0 conda-forge
wheel: 0.30.0-py36_2 conda-forge
xz: 5.2.3-0 conda-forge
zlib: 1.2.11-0 conda-forge
Proceed ([y]/n)? y
Downloading and Extracting Packages
certifi 2018.1.18: ##################################################### | 100%
setuptools 38.5.2: ##################################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use:
# > source activate example
#
# To deactivate an active environment, use:
# > source deactivate
#
Run the same test:
16:35:21 ~
§ source activate example
(example) 16:35:27 ~
§ which python
/home/evan/.conda/envs/example/bin/python
(example) 16:35:29 ~
§ python
Python 3.6.4 | packaged by conda-forge | (default, Dec 23 2017, 16:31:06)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/home/evan/.conda/envs/example/lib/python36.zip', '/home/evan/.conda/envs/example/lib/python3.6', '/home/evan/.conda/envs/example/lib/python3.6/lib-dynload', '/home/evan/.local/lib/python3.6/site-packages', '/home/evan/.conda/envs/example/lib/python3.6/site-packages']
>>>
>>> import hello
Hello World
>>>
Same behavior for .local site-packages as in root.
- 主要语言
- Shell
- 星标
- 47
- 派生
- 112
- 平均合并
- 1 天 37 分钟
- 30 天内合并 PR
- 15
环境准备
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
conda-forge/python-feedstock 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 48/100
conda-forge/python-feedstock#929 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 25/100
conda-forge/python-feedstock#903 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
conda-forge/python-feedstock#880 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 58/100
conda-forge/python-feedstock#879 ·
维护者通常 1 天内回复
-
bug
难度 3/5 1-2 天 新手友好度 38/100
conda-forge/python-feedstock#867 · 4 条评论 ·
维护者通常 1 天内回复
查看 conda-forge/python-feedstock 的全部 Issue
相似的 Issue
-
area/documentation squad/marvin
难度 1/5 1 小时以内 新手友好度 90/100
rancher/stackstate-product-docs#443 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
getumbrel/umbrel-apps#6142 ·
维护者通常 2 天内回复
-
triage/confirmed
难度 2/5 1-3 小时 新手友好度 78/100
agentscope-ai/agentscope#3030 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
WingedGuardian/GENesis-AGI#2599 ·
维护者通常 1 天内回复
-
bug good first issue
难度 2/5 1-3 小时 新手友好度 88/100
petry-projects/.github-private#1981 · 1 条评论 ·
维护者通常 1 天内回复