Select to view content in your preferred language

Installing Python module from within code inside ArcGIS Pro script tool

1850
1
Jump to solution
07-09-2018 12:14 PM
MollyMoore
Frequent Contributor

I am trying to install a third-party Python package from within a Python script so that other users can run the script and the package can be installed and loaded without having to manually download and install. This is the code I'm using:

    import subprocess
    def install(package):
        subprocess.call([sys.executable, "-m", 'pip', 'install', package])
    
    install('pyodbc')
    import pyodbc

This seems to work fine from within my stand-alone Python script. However, when I try to run it as a script tool set up in ArcGIS Pro, it is not finding the installed package and is failing with this error message:

    ModuleNotFoundError: No module named 'pyodbc'

Does anyone know what the issue is? Do I need to change a path or environment setting?

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

If you are running Pro 2.2... you will have issues since the environment is in lockdown

Search GeoNet using 'conda' as the keyword for the last 30 days to see the various discussions.

View solution in original post

1 Reply
DanPatterson_Retired
MVP Emeritus

If you are running Pro 2.2... you will have issues since the environment is in lockdown

Search GeoNet using 'conda' as the keyword for the last 30 days to see the various discussions.