Select to view content in your preferred language

Cannot import python package in Pro

503
3
01-24-2024 05:07 AM
EfiKonstantinidou
New Contributor II

Hello,

I cannot import python package opencv for use in ArcgIS Pro 3.2

I'm working in a cloned environment that is activated and package opencv seems to be pre-installed.

pavkage_manager.jpg

When importing opencv inPro  or Idle the package is not found.

pro_python.jpgidle_python.jpg

Package opencv also shows up when doing a conda list

conda_list.jpgconda_list_2.jpg

I would expect that opencv is accessible for import since it is ocntained in the conda list output.

I'm a novice, does anyone have an idea what I'm missing here?

Thanks in advance!

Efi

 

ps. I also did an additional opencv installation with conda install -c conda-forge opencv , which I deem was redundant. The problem with package import persisted

0 Kudos
3 Replies
Brian_Wilson
Regular Contributor II

You are running Idle with whatever Python environment it finds, not the Conda environment. Probably the first Python it finds in your PATH.

Try running this in your Python

import os; os.environ["CONDA_PREFIX"]

If it says KeyError: 'CONDA_PREFIX' then there is no conda environment loaded.  On my computer for example I activated the arcgispro-py3 environment and it says

'C:\\Program Files\\ArcGIS\\Pro\\bin\\Python\\envs\\arcgispro-py3'

Don't use Idle anymore. You should switch to Visual Studio Code or Spyder. I am sure there is a way to make it work properly with Idle but it's not worth the effort, get a better editor.

 

 

0 Kudos
Brian_Wilson
Regular Contributor II

Oh yeah also the startup line of the Python is a dead giveaway. It should say something like

Python 3.9.18 [MSC v.1931 64 bit (AMD64)] :: Anaconda, Inc. on win32

Look for the word "Anaconda".

 

0 Kudos
EfiKonstantinidou
New Contributor II

Thanks for replying Brian. I was out of office for a couple of days.

I tried to install and run Spyder without success first following these instructions. I got the 'version not available' error. Then I tried the not-recommended 'pip install spyder' (here , here  and here ) .

Pip install worked with warnings

EfiKonstantinidou_0-1706533396249.png

 that some required packages are not installed or there's version conflicts.

Still, Spyder appeared in the folder but doesn't launch properly (disappears and a few seconds).

I created a new (cloned) environment and did 'pip install spyder' again getting the same warnings as before (please see attached .txt )

I really don't know what else to do to make this run.

Moreover, in my prginal post I mention that I cannot import a package (opencv) in the Pro Python window as well. Isn't this a separate issue from using an IDE with Pro? I would expect that opencv can be imported using the python window even if no external IDE is used.

Thanks,

Efi

 

 

0 Kudos