如何将模块添加到 Anaconda

2022-01-10 00:00:00 python ubuntu anaconda

问题描述

这就是我执行python -V"时得到的结果

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

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

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.

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

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

我尝试按照这些步骤安装模块.

I tried to install a module following these steps.

  1. python setup.py sdist

  1. python setup.py sdist

sudo python setup.py install

sudo python setup.py install

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

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

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

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


解决方案

有几种方法可以将模块添加到 Anaconda.

There are several ways to add a module to Anaconda.

  • conda install <package>

pip install <package>

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

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

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

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 filename where 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?

相关文章