Python 如何从 Anaconda 中删除 URL 通道?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39558316/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I remove a URL channel from Anaconda?
提问by Mohammad ElNesr
Recently I needed to install PyPdf2 to one of my programs using Anaconda. Unfortunately, I failed, but the URLs that was added to Anaconda environment prohibit the updates of all the Conda libraries. Every time I tried to update anaconda it gives the following
最近我需要使用 Anaconda 将 PyPdf2 安装到我的一个程序中。不幸的是,我失败了,但是添加到 Anaconda 环境中的 URL 禁止更新所有 Conda 库。每次我尝试更新 anaconda 时,它都会给出以下信息
conda update conda
Using Anaconda Cloud api site https://api.anaconda.org
Fetching package metadata ..........Error: Invalid index file: https://pypi.python.org/pypi/PyPDF2/1.26.0/win-64/repodata.json: No JSON object could be decoded
I typed the command conda infoto see what causes the error, I found lots of URLs that points to PyPdf2!
我输入命令conda info以查看导致错误的原因,我发现了很多指向 PyPdf2 的 URL!
Simply, I want to remove all these URLS from anaconda's channel URLs, How can I do it? No matter manually or automatic.
简单地说,我想从 anaconda 的频道 URL 中删除所有这些 URL,我该怎么做?无论是手动还是自动。
Note: I have uninstalled Anaconda, and reinstall, but no luck!
注意:我已经卸载了 Anaconda,并重新安装,但没有运气!
C:\WINDOWS\system32>conda info
Using Anaconda Cloud api site https://api.anaconda.org
Current conda install:
platform : win-64
conda version : 4.1.6
conda-env version : 2.5.1
conda-build version : 1.21.3
python version : 2.7.12.final.0
requests version : 2.10.0
root environment : C:\Anaconda2 (writable)
default environment : C:\Anaconda2
envs directories : C:\Anaconda2\envs
package cache : C:\Anaconda2\pkgs
channel URLs : https://pypi.python.org/pypi/PyPDF2/1.26.0/win-64/
https://pypi.python.org/pypi/PyPDF2/1.26.0/noarch/
https://conda.anaconda.org/C:\Python27\Lib\site-packages\PyPDF2/win-64/
https://conda.anaconda.org/C:\Python27\Lib\site-packages\PyPDF2/noarch/
https://conda.anaconda.org/X:\Downloads\Compressed\PyPDF2-master\/win-64/
https://conda.anaconda.org/X:\Downloads\Compressed\PyPDF2-master\/noarch/
https://github.com/mstamy2/PyPDF2/zipball/master/win-64/
https://github.com/mstamy2/PyPDF2/zipball/master/noarch/
https://pypi.python.org/pypi/PyPDF2/win-64/
https://pypi.python.org/pypi/PyPDF2/noarch/
https://pythonhosted.org/PyPDF2/win-64/
https://pythonhosted.org/PyPDF2/noarch/
https://github.com/mstamy2/PyPDF2/win-64/
https://github.com/mstamy2/PyPDF2/noarch/
https://repo.continuum.io/pkgs/free/win-64/
https://repo.continuum.io/pkgs/free/noarch/
https://repo.continuum.io/pkgs/pro/win-64/
https://repo.continuum.io/pkgs/pro/noarch/
config file : C:\Users\Dr. Mohammad Elnesr\.condarc
offline mode : False
is foreign system : False
回答by Paul
Expanding upon Mohammed's answer.
扩展穆罕默德的回答。
All those URLs that you see in your conda info
are your channel URLs. These are where conda will look for packages. As noted by @cel, these channels can be found in the .condarc
file in your home directory.
您在您conda info
的频道中看到的所有网址都是您的频道网址。这些是 conda 将寻找包的地方。正如@cel 所指出的,这些频道可以.condarc
在您的主目录中的文件中找到。
You can interact with the channels, and other data, in your .condarc
file with the conda config
command. For example, let's say your .condarc
file lists the following channels:
您可以.condarc
使用该conda config
命令与文件中的通道和其他数据进行交互。例如,假设您的.condarc
文件列出了以下频道:
channels:
- https://github.com/mstamy2/PyPDF2/
- defaults
Then if we do conda config --get channels
we will see returned:
然后,如果我们这样做,conda config --get channels
我们将看到返回:
--add channels 'defaults' # lowest priority
--add channels 'https://github.com/mstamy2/PyPDF2/' # highest priority
If we then want to remove the github channel we would do conda config --remove channels 'https://github.com/mstamy2/PyPDF2/'
. You can also add channels through the --add
command so, for example, we could add back that channel with conda config --add channels 'https://github.com/mstamy2/PyPDF2/'
.
如果我们想删除 github 频道,我们会这样做conda config --remove channels 'https://github.com/mstamy2/PyPDF2/'
。您还可以通过--add
命令添加频道,例如,我们可以使用conda config --add channels 'https://github.com/mstamy2/PyPDF2/'
.
In this case, since there were several channels to remove, it was probably faster to simply edit the .condarc
directly but it's useful to know how to do it through conda config
.
在这种情况下,由于要删除多个通道,因此直接编辑可能会更快,.condarc
但了解如何通过conda config
.
回答by Mohammad ElNesr
Fortunately, I found the answer (Thanks to @cel as well).
幸运的是,我找到了答案(也感谢@cel)。
I navigated to C:\Users\{MyUserName}\
Then I found a file with no name but has a strange extension (.condarc
) I opened it with Notepad++, I found the files as below>
我导航到C:\Users\{MyUserName}\
然后我找到了一个没有名字但有一个奇怪的扩展名的文件(.condarc
)我用记事本++打开它,我找到了如下文件>
Then I deleted all lines except the last one, saved the file, then I ran the command conda update conda
, and it works without errors.
然后我删除了除最后一行之外的所有行,保存了文件,然后我运行了命令conda update conda
,它没有错误地工作。
回答by Lionel Yu
Hopefully my answer helps someone else out there using Mac OS terminal. I accidentally added "new_channel" to my channels list and could not figure out how to remove it. I also could not find the .condarc file (maybe someone will enlighten me please) but I was able to use the terminal to complete this.
希望我的回答可以帮助其他人使用 Mac OS 终端。我不小心将“new_channel”添加到我的频道列表中,但不知道如何删除它。我也找不到 .condarc 文件(也许有人会启发我)但我能够使用终端来完成这个。
There's two types of "channels" in Conda. One is the channels and one is the channel URLs. If you're trying to delete the the channel URL, you cannot delete it using:
Conda 中有两种类型的“通道”。一种是渠道,一种是渠道 URL。如果您尝试删除频道 URL,则无法使用以下方法将其删除:
conda config --remove channels
Originally I typed conda info
and saw the following:
最初我输入conda info
并看到以下内容:
channel URLs :
频道网址:
https://repo.anaconda.com/pkgs/pro/osx-64
https://repo.anaconda.com/pkgs/pro/noarch
https://conda.anaconda.org/new_channel/osx-64
https://conda.anaconda.org/new_channel/noarch
So I was thinking, ok, let me just type in the following.
所以我在想,好吧,让我输入以下内容。
conda config --remove channels https://conda.anaconda.org/new_channel/osx-64
THIS DOES NOT WORK.
这不起作用。
What you have to do is type in the following:
您需要做的是输入以下内容:
conda config --show channels
You will see your channels:
您将看到您的频道:
channels:
渠道:
defaults
new_channel
默认值
新频道
Now you know what your channel is called. It's called new_channel (may seem obvious, but sometimes not to us beginners).
现在你知道你的频道叫什么了。它被称为 new_channel (可能看起来很明显,但有时对我们初学者来说不是)。
So you type in:
所以你输入:
conda config --remove channels new_channel
And boom, all the new_channel URLs are gone.
砰,所有的 new_channel URL 都消失了。
In OP's case, his channel was most likely called PyPdf2
在 OP 的案例中,他的频道很可能被称为 PyPdf2
So the correct code to type into Terminal is:
所以输入终端的正确代码是:
conda config --remove channels PyPdf2
AGAIN, DON'T TRY TO DELETE THE CHANNEL URL. MAKE SURE YOU DELETE THE CHANNEL ITSELF.
再次强调,不要尝试删除频道 URL。确保您删除频道本身。