久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

conda環(huán)境有訪問系統(tǒng)模塊,如何防止?

conda environment has access to system modules, how to prevent?(conda環(huán)境有訪問系統(tǒng)模塊,如何防止?)
本文介紹了conda環(huán)境有訪問系統(tǒng)模塊,如何防止?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我注意到,當(dāng)我使用 conda 創(chuàng)建新環(huán)境時(shí),我可以在該環(huán)境中導(dǎo)入未安裝的 python 模塊.

I noticed that when I create a new enviornment with conda, I can import python modules in that environment that were NOT installed there.

以 keras 為例:雖然模塊不在那個(gè)環(huán)境中:

Example with keras: Although the module is NOT in that enviornment:

(py2) user@user-Precision-7920-Tower:~$ conda list keras
# packages in environment at /home/user/anaconda3/envs/py2:
#
# Name                    Version                   Build  Channel

我仍然可以導(dǎo)入它,顯然是從系統(tǒng)(用戶)安裝,在 conda 之外!

I can still import it, apparently from the system (user) install, outside conda!

(py2) user@user-Precision-7920-Tower:~$ python
Python 2.7.15 | packaged by conda-forge | (default, Mar  5 2020, 14:56:06) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> import keras
Using TensorFlow backend.
>>> keras.__file__
'/home/user/.local/lib/python2.7/site-packages/keras/__init__.pyc'

其實(shí)conda里面的python是可以訪問非conda路徑的!

In fact, python inside conda has access to non-conda paths!

>>> import sys
>>> 
>>> sys.stdout.write("
".join(sys.path))

/home/user/anaconda3/envs/py2/lib/python27.zip
/home/user/anaconda3/envs/py2/lib/python2.7
/home/user/anaconda3/envs/py2/lib/python2.7/plat-linux2
/home/user/anaconda3/envs/py2/lib/python2.7/lib-tk
/home/user/anaconda3/envs/py2/lib/python2.7/lib-old
/home/user/anaconda3/envs/py2/lib/python2.7/lib-dynload
/home/user/.local/lib/python2.7/site-packages               <-- 
/home/user/anaconda3/envs/py2/lib/python2.7/site-packages>>> 

Conda 應(yīng)該保持隔離.這條路是怎么走到這里的,如何避免這種情況發(fā)生?

Conda is supposed to keep things isolated. How did this path endd up in here, and how to avoid this from happening?

更新:

我的用戶級(jí) python 是 2.7,我注意到當(dāng)我使用 python 2.7 創(chuàng)建新的 conda 環(huán)境時(shí)總是會(huì)發(fā)生這種行為,這只是自動(dòng)將 .local/lib/python2.7/site-packages 添加到 PYTHONPATH.

My user-level python is 2.7, and I noticed this behavior always happen when I create a new conda environment with python 2.7, this just automatically adds the .local/lib/python2.7/site-packages to PYTHONPATH.

如果我使用 python3.x 創(chuàng)建新的 conda 環(huán)境,則不會(huì)發(fā)生這種情況.

If I create new conda environments with python3.x , this does not happen.

這是否意味著不能為與用戶級(jí) python 相同的 python 版本創(chuàng)建單獨(dú)的隔離 conda 環(huán)境?

Does this mean that one cannot create a separate isolated conda environment for the same python version as the user-level python?

推薦答案

除了 @VikashB 提到的之外,這些可能是使用 pip install --user 安裝的軟件包造成的.正如@TimRoberts 在評(píng)論中提到的那樣,填充 sys.path 變量的 site 模塊會(huì)搜索像 ~/.local/lib/python* 這樣的路徑/site-packages 默認(rèn)情況下.

In addition to what @VikashB mentioned, these can result from packages installed with pip install --user. As @TimRoberts alluded to in the comments, the site module, which populates the sys.path variable, searches paths like ~/.local/lib/python*/site-packages by default.

如果您出于某種原因需要保留這些包,則需要將它們移動(dòng)到非默認(rèn)位置,以便 site 模塊找不到它們.例如,

If you need to keep these packages for some reason, you'll need to move them to a non-default location so the site module doesn't find them. For example,

mkdir ~/.local/lib/py_backup
mv ~/.local/lib/python* ~/.local/lib/py_backup

這將有效地隱藏它們,如果需要,它們?nèi)匀豢梢酝ㄟ^ PYTHONPATH 使用.

This will effectively hide them, and they could still be used through PYTHONPATH if necessary.

否則,只需刪除它們,即,

Otherwise, just remove them, i.e.,

rm -r ~/.local/lib/python*

作為參考,不鼓勵(lì) Conda 用戶使用 --user 標(biāo)志guide/tasks/manage-environments.html#pip-in-env" rel="nofollow noreferrer">Conda 文檔.Conda 環(huán)境假設(shè)環(huán)境完全隔離,因此 OP 報(bào)告等泄漏可能導(dǎo)致未定義的行為.

For reference, Conda users are discouraged from using the --user flag in the Conda documentation. Conda environments assume full isolation of environments, so leakage such as OP reports can lead to undefined behavior.

這篇關(guān)于conda環(huán)境有訪問系統(tǒng)模塊,如何防止?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Troubles while parsing with python very large xml file(使用 python 解析非常大的 xml 文件時(shí)出現(xiàn)問題)
Find all nodes by attribute in XML using Python 2(使用 Python 2 在 XML 中按屬性查找所有節(jié)點(diǎn))
Python - How to parse xml response and store a elements value in a variable?(Python - 如何解析 xml 響應(yīng)并將元素值存儲(chǔ)在變量中?)
How to get XML tag value in Python(如何在 Python 中獲取 XML 標(biāo)記值)
How to correctly parse utf-8 xml with ElementTree?(如何使用 ElementTree 正確解析 utf-8 xml?)
Parse XML from URL into python object(將 XML 從 URL 解析為 python 對象)
主站蜘蛛池模板: 五月精品视频 | 日韩男人天堂 | 中文字幕亚洲区 | 一级aaaa毛片 | 在线播放一区 | 黄色毛片在线看 | 精品久久国产视频 | 亚洲一区二区三区视频免费观看 | 九七午夜剧场福利写真 | www.国产精| 色综合中文 | 四色成人av永久网址 | 久久精品一区 | 免费观看一级毛片 | 精品久久香蕉国产线看观看亚洲 | 日本精品一区二区三区在线观看视频 | 精品久久国产老人久久综合 | 日韩在线国产精品 | 亚州精品天堂中文字幕 | 欧美日韩国产在线观看 | 精品av天堂毛片久久久借种 | 久久婷婷麻豆国产91天堂 | 欧美综合一区 | 久久久久久蜜桃一区二区 | 欧美综合久久 | 美女天天干天天操 | 亚洲精品中文字幕在线观看 | 久久久久免费 | 福利视频一区二区 | www.99re| 国产精品久久久久久久久久久久 | 狼色网 | 国产精品免费一区二区三区四区 | 丝袜毛片| 亚洲精品一二三区 | 成人国产精品久久 | 精品视频在线免费观看 | 亚洲精品一 | 成人国产一区二区三区精品麻豆 | 欧美一区二区三区在线免费观看 | 极品的亚洲 |