user1470957
user1470957

Reputation: 461

build conda package from local python package

I can't find a complete example of how to create a conda package from a python package that I wrote and also how to install the package using conda install, while it is on my computer and not on anaconda cloud. I'm looking for example that not using conda skeleton from pypi, but using a python package on my windows machine, the source code must be on my windows machine and not on pypi or other cloud. any help would be mostly appriciate. thanks very much

Upvotes: 22

Views: 17270

Answers (4)

Asta86
Asta86

Reputation: 401

A local source directory can be specified in the metadata file meta.yaml by using:

  source:
     path: ../src

https://docs.conda.io/projects/conda-build/en/latest/resources/define-metadata.html#source-from-a-local-path

Additionally, to package your own program you have to define the steps needed to build and install it (for instance, running setup.py install for a python script that uses setuptools: https://setuptools.readthedocs.io/en/latest/index.html) in the files build.sh for linux and bld.bat for windows.

Upvotes: 4

Joshua Patterson
Joshua Patterson

Reputation: 693

I found some helpful information on the Anaconda Enterprise doc. The two videos linked:

are the best things I found in my searching.

Upvotes: 0

Charlie Parker
Charlie Parker

Reputation: 5219

I think it should be trivial if you use the editable way to install packages with conda. I did:

conda develop .

in the project directory (where my setup.py file is).

If you want an example of a setup.py here is mine:

from setuptools import setup
from setuptools import find_packages

setup(
    name='ml', #project name
    version='0.1.0',
    description='ML',
    #url
    author='Me',
    author_email='[email protected]', #not a real e-mail
    license='MIT',
    packages=find_packages(),
    install_requires=['torch','numpy','scikit-learn','scipy','matplotlib','pyyml']
)

The file above is at the root of the project (I do a github repo named project and inside I make a project project with all the packages I develop there.

I believe pip -e . will do the same. You shouldn't need to sudo anything.

Upvotes: 7

Christoph
Christoph

Reputation: 5612

You can use python setup.py bdist_conda to easily generate a conda package from your local python package, even without a recipe:

You can use conda build to build packages for Python to install rather than conda, by using setup.py bdist_conda. This is a quick way to build packages without using a recipe, but it has limitations. The script is limited to the Python version used in the build, and it is not as reproducible as using a recipe. We recommend using a recipe with conda build.

https://docs.conda.io/projects/conda-build/en/latest/user-guide/recipes/build-without-recipe.html

Upvotes: 3

Related Questions