Python 如何将模块添加到 Anaconda

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35436350/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 16:26:48  来源:igfitidea点击:

how to add a module to Anaconda

pythonubuntuanaconda

提问by sanjith kumar

This is what i get when i do "python -V"

这就是我在执行“ python -V”时得到的结果

Python 2.7.11 :: Anaconda 2.4.0 (64-bit)I usually use my terminal to play with IDLE.But now i have also installed IDLE shell.

Python 2.7.11 :: Anaconda 2.4.0 (64-bit)我通常使用我的终端来玩 IDLE。但现在我也安装了 IDLE shell。

I tried import sys;sys.pathon both.They throw different paths. My Terminal returned the path with anaconda in it.

我在两者上都尝试了import sys;sys.path。他们抛出了不同的路径。我的终端返回了包含 anaconda 的路径。

I tried to install a module following these steps.

我尝试按照这些步骤安装一个模块。

  1. python setup.py sdist

  2. sudo python setup.py install

  1. python setup.py sdist

  2. 须藤 python setup.py 安装

Then i opened IDLE(shell).I was able to import and also use my module.

然后我打开了 IDLE(shell)。我能够导入并使用我的模块。

I wanna do the same in Anaconda..I tried using conda install filename.py.It doesn't work. Please help.

我想在 Anaconda 中做同样的事情..我尝试使用 conda install filename.py.它不起作用。请帮忙。

采纳答案by Back2Basics

There are several ways to add a module to Anaconda.

有多种方法可以将模块添加到 Anaconda。

  • conda install <package>

  • pip install <package>

  • python setup.py install(if you are in the source directory, no sudo required if anaconda is in your home directory)
  • conda install <package>

  • pip install <package>

  • python setup.py install(如果您在源目录中,如果 anaconda 在您的主目录中,则不需要 sudo)

To make a package for others to use you will need to put it up where people can access it like Github. You will have to make a config file (takes yaml file manipulation) you can read up on how to make/distribute packages here. http://conda.pydata.org/docs/build_tutorials/pkgs.html

要制作一个供其他人使用的包,您需要将它放在人们可以像 Github 一样访问的地方。您必须制作一个配置文件(需要 yaml 文件操作),您可以在此处阅读有关如何制作/分发包的信息。http://conda.pydata.org/docs/build_tutorials/pkgs.html

Now to answer your question: There is a difference between using a file and using a module/package. A file can just be imported in another python program using import filenamewhere filename.py is the name of the file you want to use. to make that a module you want to take a look at the answer to this question. How to write a Python module?

现在回答您的问题:使用文件和使用模块/包之间存在差异。可以使用import filename其中 filename.py 是您要使用的文件的名称将文件导入到另一个 python 程序中。使它成为一个模块,你想看看这个问题的答案。如何编写 Python 模块?

回答by user

I agree with the answer above. But just be careful when using: pip install Apparently a deprecated pip could generate problems like "Could not find a version that satisfies the requirement" So just to be on the safe side update your version.

我同意楼上的回答。但是在使用时要小心: pip install 显然,不推荐使用的 pip 可能会产生诸如“找不到满足要求的版本”之类的问题,所以为了安全起见,请更新您的版本。

That was my case. After looking at this link: https://pypi.org/project/opencv-python/

这就是我的情况。查看此链接后:https: //pypi.org/project/opencv-python/

It said:

它说:

A: Most likely the issue is related to too old pip and can be fixed by running
pip install --upgrade pip.

A:问题很可能与 pip 太旧有关,可以通过运行
pip install --upgrade pip.

So I decided to try updating mine. And it worked...
Hope this was helpful!

所以我决定尝试更新我的。它有效......
希望这有帮助!