0

I am currently using ArcGIS Pro 3.0. I have a script that once worked well with ArcGIS Desktop and utilized ArcPy and psycopg2 libraries.

I understand now it is required to use propy.bat file path when trying to use stand alone scripts like below.

c:\Progra~1\ArcGIS\Pro\bin\Python\scripts\propy.bat my_script.py

When I execute my script this way I get 'No module named 'psycopg2''.

However I am confident psycopg2 is installed. I can verify this by starting python in terminal and running import psycopg2 without error.

enter image description here

Is there something special that needs to be done to execute a script using both libraries with ArcGIS Pro 3?

1
  • "starting python in terminal," which terminal exactly? Do you have multiple Python installations on the machine because ArcGIS Pro 3.0 is bundled with Python 3.9.11, and the screenshot shows 3.7.9.
    – bixb0012
    Jul 17, 2022 at 13:14

2 Answers 2

1

Psycopg is a PostgreSQL database adapter for Python.

In ArcGIS Pro, you can to download/install PostgreSQL client libraries from the Products Menu as described here : https://support.esri.com/en/technical-article/000012190.

Note : Make sure after the install to remove import psycopg2 before re-executing your script.

1
  • Thx but then I get NameError: name 'psycopg2' is not defined.. When psycopg2.connect() is called? @M92_ Jul 17, 2022 at 16:10
0

Using the propy.bat file will ensure that the script is run using the currently-set conda environment, as defined in the ArcGIS Pro settings.

So make sure the desired environment is set and has the psycopg2 package installed. To check the settings, open ArcGIS Pro and go to the backstage/settings menu -> Python -> Installed Packages. If you don't see it listed you can use the Add Packages option to install it (you may need to clone the default environment first).

View of ArcGIS Pro settings panel showing the python packages for the currently selected environment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.