Select to view content in your preferred language

conda build recipe -c esri results in AttributeError

315
2
09-19-2024 07:13 AM
JaredPilbeam2
MVP Regular Contributor

Tutorial One

@HannesZiegler 

Thanks for posting the helpful tutorials. I've never been able to share Pro script tools outside of my machine before, so I'm hoping this allows me to.

I'm on Tutorial Two but got stuck. I got as far as step 3 under Build the package. "scripttools" is my build-distribute environment. When I run conda build recipe -c esri it throws an error.

 

(scripttools) PS C:\WINDOWS\system32> cd \\shareddirectory\postoffice
(scripttools) PS Microsoft.PowerShell.Core\FileSystem::\\shareddirectory\postoffice> conda build recipe -c esri
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\conda_build\conda_interface.py", line 14, in try_exports
    return getattr(import_module('conda.exports'), attr)
AttributeError: module 'conda.exports' has no attribute 'get_prefix'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\Scripts\conda-build-script.py", line 6, in <module>
    from conda_build.cli.main_build import main
  File "C:\ProgramData\Anaconda3\lib\site-packages\conda_build\cli\main_build.py", line 18, in <module>
    import conda_build.api as api
  File "C:\ProgramData\Anaconda3\lib\site-packages\conda_build\api.py", line 22, in <module>
    from conda_build.config import (Config, get_or_merge_config, get_channel_urls,
  File "C:\ProgramData\Anaconda3\lib\site-packages\conda_build\config.py", line 15, in <module>
    from .conda_interface import root_dir, root_writable
  File "C:\ProgramData\Anaconda3\lib\site-packages\conda_build\conda_interface.py", line 119, in <module>
    context_get_prefix = try_exports("conda.base.context", "get_prefix")
  File "C:\ProgramData\Anaconda3\lib\site-packages\conda_build\conda_interface.py", line 16, in try_exports
    return getattr(import_module(module), attr)
AttributeError: module 'conda.base.context' has no attribute 'get_prefix'
(scripttools) PS Microsoft.PowerShell.Core\FileSystem::\\shareddirectory\postoffice>

 

I've attempted to update the conda-build package, but I'm getting conflicting results. Like, it lists the conda version as 24.7.1 in the environment, but it's warning me to update? After the update, I still get the error.

 

(scripttools) PS C:\WINDOWS\system32> conda update conda-build
Collecting package metadata (current_repodata.json): done
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 23.9.0
  latest version: 24.7.1

Please update conda by running

    $ conda update -n base -c defaults conda

Or to minimize the number of packages updated during conda update use

     conda install conda=24.7.1



# All requested packages already installed.

(scripttools) PS C:\WINDOWS\system32> conda list
# packages in environment at C:\ProgramData\Anaconda3\envs\scripttools:
#
# Name                    Version                   Build  Channel
anaconda-anon-usage       0.4.4           py39hfc23b7f_100
anaconda-client           1.12.3           py39haa95532_0
archspec                  0.2.3              pyhd3eb1b0_0
attrs                     23.1.0           py39haa95532_0
beautifulsoup4            4.12.3           py39haa95532_0
boltons                   23.0.0           py39haa95532_0
brotli-python             1.0.9            py39hd77b12b_8
bzip2                     1.0.8                h2bbff1b_6
ca-certificates           2024.7.2             haa95532_0
certifi                   2024.8.30        py39haa95532_0
cffi                      1.16.0           py39h2bbff1b_1
chardet                   4.0.0           py39haa95532_1003
charset-normalizer        3.3.2              pyhd3eb1b0_0
click                     8.1.7            py39haa95532_0
colorama                  0.4.6            py39haa95532_0
conda                     24.7.1           py39haa95532_0
conda-build               24.7.1           py39haa95532_0
conda-index               0.5.0            py39haa95532_0
conda-libmamba-solver     24.7.0             pyhd3eb1b0_0
conda-package-handling    2.3.0            py39haa95532_0
conda-package-streaming   0.10.0           py39haa95532_0

 

0 Kudos
2 Replies
DavidSolari
Frequent Contributor

If you have to publish this to a public repository then you might want to crosspost on a dedicated Conda forum, they should have more insight into the build system than the average ESRI user.

That said, if you aren't uploading to a public system then there's a much easier way to fix your issues with conda's build system: just don't use it! Here's the cliff notes on using Python's standard packaging model:

  1. Install the "build" package to the Python environment you're using for development.
  2. Grab the folder that contains your package folder ("mailbox" in the example workflow) and add:
    • Two empty folders, "build" and "dist"
    • An empty file named "pyproj.toml"
    • Your README.md (and your LICENSE file if this is leaving your company's control).
    You don't need anything to do with a recipe folder, nor do you need a top-level directory.
  3. Fill out your pyproj.toml as per the official guides, with extra configuration for setuptools as per its guide. The key part is your [build-system] section, this specifies your build dependencies and your build system. Mine looks like:

    [build-system]
    requires = ["setuptools >= 68.2.1","wheel"]
    build-backend = "setuptools.build_meta"

    Most of the other sections should be easy to fill out, if you run into issues with your package missing key files you can try adding:

    [tool.setuptools.package-data]
    "*" = ["esri/**"]


  4. Pop open the Python Command Prompt and run python -m build "C:\path\to\mailbox". You should now have a "tar.gz" file and a "whl" file in your "dist" folder.
  5. With the command prompt open, run pip install "C:\path\to\mailbox\dist\artifact_name.whl". This will install the package to your environment.
  6. Restart Pro and ensure you can import your module and run the installed script tools. If you can import the module but the tools fail, ensure that "esri" subfolder has all the necessary files and they're included in your "whl" file -- you can crack the whl files open with 7Zip to browse their contents to check.

And there you go, now you can build and deploy your packages using pip instead of conda! The one catch is dependencies: pip will get dependencies from pypi.org instead of the dedicated conda channel, so you could clobber your environment by accident. To avoid this, always check if a dependency is available on conda and then specify that exact version in your pyproj file. You don't have to specify arcpy or any ESRI-specific dependencies if you aren't publishing to a public repository as they're a part of every Pro environment. As a bonus, you now have access to packages outside of the esri conda channel if you need extra functionality.

0 Kudos
JaredPilbeam2
MVP Regular Contributor

Thanks for the info. I mean, if I can avoid posting to a public place I would. All I plan to do is share within our office. I started out just saving the toolbox and its script on a shared network drive, but was constantly met with an OSError from the tool when ran from my colleague's machine.

0 Kudos