conda安装python库_如何通过conda安装我自己的python模块(软件包)并观察其更改...

I have a file mysql.py, which I use in almost all of my projects. Since I do not want to copy and paste the same file into each of these projects I wrote a module - possibly a package in the future.

Question

How do I add a local module to my conda environment, and automatically update or watch it when I change something in mysql.py? How to do the same for a package?

I would like to avoid to set up a local channel/repository and just reference to the folder with mysql.py.

解决方案

While the previous answers are doing what I need, I just want to show what I will be using instead. Since it was my plan to learn about conda packages anyway...

0. Good sources

1. Create a python package template for conda using cookiecutter

conda install -c conda-forge cookiecutter

Now change to the directory where you want to initialize your package, then do:

cookiecutter https://github.com/conda/cookiecutter-conda-python.git

This will ask for some basic information about the package that you want to create. Then change into your repo

cd myrepo

2. Build your package

make sure conda-build is installed, if not run

conda install conda-build

Make sure to set the CONDA_BLD_PATH as mentioned in anaconda - using a different conda-build root directory - Stack Overflow. This will be the directory where you can find your packages, then run:

conda build conda.recipe

to build your package and clean up after you with

conda build purge

3. Set up your own local channel (no uploading to anaconda.org)

Read

for help.

Index each platform. Maybe someone can confirm that this step is not needed, as my builds already contain the repodata.json. Otherwise:

conda index D:\CODE\condamychannel\win-64

Test if the package can be found with

conda search -c file:///D:\CODE\condamychannel --override-channels mypackage

or add the channel to the config directly (per environment)

conda config --add channels file:///D:\CODE\condamychannel

4. Install (and update) the package

activate myenv

and

conda install mypackage

Once I change mypackage, I give it a new version number in meta.yaml and setup.py and build the package with conda build conda.recipe.

Updating is simply

conda update mypackage

See if your package works:

python

>>> import cli from mypackage

>>> cli.cli()

CLI template

This may not be the optimal way, but I could not find a tutorial that contains all the steps I outlined above.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值