Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: Hunter on May 29, 2019, 04:05:49 PM

Title: External python modules not found
Post by: Hunter on May 29, 2019, 04:05:49 PM
I'm having trouble installing external python modules to Metashape and hoping someone can provide some insight.  I've read the Metashape manual and Python addendum and have tried the following:

1.
Code: [Select]
$.../metashape-pro/python/bin$ ./python3.5 -m pip install Pillow
Requirement already satisfied: Pillow in /usr/local/lib/python3.7/dist-packages (6.0.0)

(similar results for module Image and module exifread)

Next, I start Metashape and attempt to run my script by clicking tools->run script (script starts with the following lines and errors on line 2):
Code: [Select]
import Metashape
from PIL import Image
import PIL.ExifTags

and get the message box "No module named 'PIL'"

2. I installed libssl 0.9.8 (as shown on https://agisoft.freshdesk.com/support/solutions/articles/31000136860-how-to-install-external-python-module-to-metashape-professional-package (https://agisoft.freshdesk.com/support/solutions/articles/31000136860-how-to-install-external-python-module-to-metashape-professional-package))

3. Tried #1 again, but same result.

4. One oddity, when I type:
Code: [Select]
$.../metashape-pro/python/bin$ ./python3.5
Python 3.7.3 (default, Apr  3 2019, 05:39:12)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Notice that it runs the default python install on my machine (3.7.3).


5.
Code: [Select]
$.../metashape-pro/python/bin$ ./pip install Pillow
bash: ./pip: /opt/python3.5/bin/python3.5m: bad interpreter: No such file or directory

6.
Code: [Select]
$uname -a
Linux <computername> 5.0.0-15-generic #16-Ubuntu SMP Mon May 6 17:41:33 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Any ideas? (Thanks in advance)
Title: Re: External python modules not found
Post by: Alexey Pasumansky on May 29, 2019, 10:17:01 PM
Hello Hunter,

Which OS version you are using?

It seems that there's something messed up with the dependencies. I've tried to follow the same approach and have properly installed Pillow on the clean Ubuntu system, and the module is working from Metashape console now.
Title: Re: External python modules not found
Post by: Hunter on May 30, 2019, 07:03:54 PM
Code: [Select]
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 19.04
Release: 19.04
Codename: disco


Thanks for the quick response.
Title: Re: External python modules not found
Post by: Alexey Pasumansky on May 31, 2019, 09:03:58 PM
Hello Hunter,

Can you please execute the following command from the Metashape Pro installation directory:
Code: [Select]
LD_LIBRARY_PATH=`pwd`/python/lib python/bin/python3.5 --version
If it shows Python 3.5.2, please try the installation using the following commands:
Code: [Select]
cd <path_to_metashape-pro>
LD_LIBRARY_PATH=`pwd`/python/lib ./python/bin/python3.5 -m pip install python_module_name
Title: Re: External python modules not found
Post by: Hunter on June 03, 2019, 02:39:39 AM
Thanks Alexey.

I was able to eventually solve the problem by rolling back to Ubuntu 18.04.  Desktop install with nothing special.  I then copied libpython3.5m.so.1.0 to the metashape/python/bin folder.  Finally, I ran...

Code: [Select]
sudo ./python3.5 -m pip install Pillow
and it installed correctly.  I then started Metashape and my python script to extract and use metadata in the EXIF fields worked great.  Thanks again for the support!
Title: Re: External python modules not found
Post by: ashalota on April 17, 2020, 04:58:18 AM
Hello Hunter,

Can you please execute the following command from the Metashape Pro installation directory:
Code: [Select]
LD_LIBRARY_PATH=`pwd`/python/lib python/bin/python3.5 --version
If it shows Python 3.5.2, please try the installation using the following commands:
Code: [Select]
cd <path_to_metashape-pro>
LD_LIBRARY_PATH=`pwd`/python/lib ./python/bin/python3.5 -m pip install python_module_name

I am having this same issue. I followed these instructions, but now I am stuck at the issue that is mentioned in the link posted at the top for external library install:

Quote
In case Linux installation doesn't work due to any reason (like ImportError: cannot import name 'HTTPSHandler') please install libssl 0.9.8 (as shown below) and repeat pip install process:

wget http://snapshot.debian.org/archive/debian/20110406T213352Z/pool/main/o/openssl098/libssl0.9.8_0.9.8o-7_amd64.deb

sudo dpkg -i libssl0.9.8_0.9.8o-7_amd64.deb

I don't have sudo on my machine though, is there any other good solution?
Title: Re: External python modules not found
Post by: ashalota on April 25, 2020, 01:09:51 AM
Hi I figured it out. I needed to include a different python lib for LD_LIBRARY_PATH as well, since the metashape (1.6.2 pro) version I have installed had the HTTPSHandler issue.

Code: [Select]
LD_LIBRARY_PATH=/path/to/metashape-pro/python/lib:/path/to/anaconda3/envs/py35/lib; metashape-pro/python/bin/python3.5 -m pip install python_module_name

this finally worked
Title: Re: External python modules not found
Post by: rmassaro on May 25, 2020, 10:32:00 PM
I'm having the same error with Ubuntu 20.04 and Metashape 1.5.5:
ImportError: cannot import name 'HTTPSHandler'

I installed libssl according to https://agisoft.freshdesk.com/support/solutions/articles/31000136860-how-to-install-external-python-module-to-metashape-professional-package (https://agisoft.freshdesk.com/support/solutions/articles/31000136860-how-to-install-external-python-module-to-metashape-professional-package)

Default Python is 3.8 but even did an alt install of 3.5.2. Still getting the same HTTPSHandler error when running this command:
Code: [Select]
LD_LIBRARY_PATH=/usr/local/metashape-pro/python/lib:/usr/local/bin/python3.5:/usr/local/lib/python3.5:/usr/lib/x86_64-linux-gnu ./python3.5 -m pip install numpy
Should I revert back to an earlier Ubuntu release and/or upgrade to the latest Metashape? (Dragging my feet on upgrading to latest Metashape because it would involve rewriting a lot of code for the API..)
Title: Re: External python modules not found
Post by: rmassaro on May 26, 2020, 02:19:36 PM
I'm having the same error with Ubuntu 20.04 and Metashape 1.5.5:
ImportError: cannot import name 'HTTPSHandler'

I installed libssl according to https://agisoft.freshdesk.com/support/solutions/articles/31000136860-how-to-install-external-python-module-to-metashape-professional-package (https://agisoft.freshdesk.com/support/solutions/articles/31000136860-how-to-install-external-python-module-to-metashape-professional-package)

Default Python is 3.8 but even did an alt install of 3.5.2. Still getting the same HTTPSHandler error when running this command:
Code: [Select]
LD_LIBRARY_PATH=/usr/local/metashape-pro/python/lib:/usr/local/bin/python3.5:/usr/local/lib/python3.5:/usr/lib/x86_64-linux-gnu ./python3.5 -m pip install numpy
Should I revert back to an earlier Ubuntu release and/or upgrade to the latest Metashape? (Dragging my feet on upgrading to latest Metashape because it would involve rewriting a lot of code for the API..)


As an update, I'm seeing the same "HTTPSHandler" issue with Ubuntu 20.04 and the latest Metashape (1.6.2)

Title: Re: External python modules not found
Post by: rmassaro on May 26, 2020, 07:01:26 PM
I'm having the same error with Ubuntu 20.04 and Metashape 1.5.5:
ImportError: cannot import name 'HTTPSHandler'

I installed libssl according to https://agisoft.freshdesk.com/support/solutions/articles/31000136860-how-to-install-external-python-module-to-metashape-professional-package (https://agisoft.freshdesk.com/support/solutions/articles/31000136860-how-to-install-external-python-module-to-metashape-professional-package)

Default Python is 3.8 but even did an alt install of 3.5.2. Still getting the same HTTPSHandler error when running this command:
Code: [Select]
LD_LIBRARY_PATH=/usr/local/metashape-pro/python/lib:/usr/local/bin/python3.5:/usr/local/lib/python3.5:/usr/lib/x86_64-linux-gnu ./python3.5 -m pip install numpy
Should I revert back to an earlier Ubuntu release and/or upgrade to the latest Metashape? (Dragging my feet on upgrading to latest Metashape because it would involve rewriting a lot of code for the API..)


As an update, I'm seeing the same "HTTPSHandler" issue with Ubuntu 20.04 and the latest Metashape (1.6.2)

SOLVED (for now): As another update, this works perfectly normally with Ubuntu 18.04. So, I would suggest sticking with the older Ubuntu release until a workaround for 20.04 is determined.
Title: Re: External python modules not found
Post by: dobedobedo on July 30, 2020, 07:02:53 AM
Hi,
The same thing happened here on Arch Linux. I already installed either the openssl098 as suggested https://agisoft.freshdesk.com/support/solutions/articles/31000136860-how-to-install-external-python-module-to-photoscan-professional-pacakge (https://agisoft.freshdesk.com/support/solutions/articles/31000136860-how-to-install-external-python-module-to-photoscan-professional-pacakge) or the latest openssl, but still got the HTTPSHandler error. Here's the command and output I tried to execute:
command:
Code: [Select]
LD_LIBRARY_PATH=/opt/agisoft/metashape-pro/python/lib /opt/agisoft/metashape-pro/python/bin/python3.5 -m pip install --user Pillowoutput:
Code: [Select]
Traceback (most recent call last):
  File "/opt/agisoft/metashape-pro/python/lib/python3.5/runpy.py", line 174, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/opt/agisoft/metashape-pro/python/lib/python3.5/runpy.py", line 133, in _get_module_details
return _get_module_details(pkg_main_name, error)
  File "/opt/agisoft/metashape-pro/python/lib/python3.5/runpy.py", line 109, in _get_module_details
__import__(pkg_name)
  File "/opt/agisoft/metashape-pro/python/lib/python3.5/site-packages/pip/__init__.py", line 16, in <module>
from pip.vcs import git, mercurial, subversion, bazaar  # noqa
  File "/opt/agisoft/metashape-pro/python/lib/python3.5/site-packages/pip/vcs/subversion.py", line 9, in <module>
from pip.index import Link
  File "/opt/agisoft/metashape-pro/python/lib/python3.5/site-packages/pip/index.py", line 30, in <module>
from pip.wheel import Wheel, wheel_ext
  File "/opt/agisoft/metashape-pro/python/lib/python3.5/site-packages/pip/wheel.py", line 39, in <module>
from pip._vendor.distlib.scripts import ScriptMaker
  File "/opt/agisoft/metashape-pro/python/lib/python3.5/site-packages/pip/_vendor/distlib/scripts.py", line 14, in <module>
from .compat import sysconfig, detect_encoding, ZipFile
  File "/opt/agisoft/metashape-pro/python/lib/python3.5/site-packages/pip/_vendor/distlib/compat.py", line 66, in <module>
from urllib.request import (urlopen, urlretrieve, Request, url2pathname,
ImportError: cannot import name 'HTTPSHandler'

The metashape-pro version is 1.6.3, and I believe I used the correct python
Code: [Select]
$ LD_LIBRARY_PATH=/opt/agisoft/metashape-pro/python/lib /opt/agisoft/metashape-pro/python/bin/python3.5 --version
Python 3.5.2

Any suggestions to resolve this issue would be appreciated.
Title: Re: External python modules not found
Post by: dobedobedo on August 07, 2020, 06:49:13 AM
Hi @Alexey,
Just would like to know if your team started to investigate this? It seems that this issue affects many users. However, unlike Ubuntu users who can choose to roll back to an older release, users like Arch just simply can't resolve this issue by doing so. I looked up online and some answers suggested that it may be related to some out-dated virtual environment script. Hope this information help.

Hi,
The same thing happened here on Arch Linux. I already installed either the openssl098 as suggested https://agisoft.freshdesk.com/support/solutions/articles/31000136860-how-to-install-external-python-module-to-photoscan-professional-pacakge (https://agisoft.freshdesk.com/support/solutions/articles/31000136860-how-to-install-external-python-module-to-photoscan-professional-pacakge) or the latest openssl, but still got the HTTPSHandler error. Here's the command and output I tried to execute:
command:
Code: [Select]
LD_LIBRARY_PATH=/opt/agisoft/metashape-pro/python/lib /opt/agisoft/metashape-pro/python/bin/python3.5 -m pip install --user Pillowoutput:
Code: [Select]
Traceback (most recent call last):
  File "/opt/agisoft/metashape-pro/python/lib/python3.5/runpy.py", line 174, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/opt/agisoft/metashape-pro/python/lib/python3.5/runpy.py", line 133, in _get_module_details
return _get_module_details(pkg_main_name, error)
  File "/opt/agisoft/metashape-pro/python/lib/python3.5/runpy.py", line 109, in _get_module_details
__import__(pkg_name)
  File "/opt/agisoft/metashape-pro/python/lib/python3.5/site-packages/pip/__init__.py", line 16, in <module>
from pip.vcs import git, mercurial, subversion, bazaar  # noqa
  File "/opt/agisoft/metashape-pro/python/lib/python3.5/site-packages/pip/vcs/subversion.py", line 9, in <module>
from pip.index import Link
  File "/opt/agisoft/metashape-pro/python/lib/python3.5/site-packages/pip/index.py", line 30, in <module>
from pip.wheel import Wheel, wheel_ext
  File "/opt/agisoft/metashape-pro/python/lib/python3.5/site-packages/pip/wheel.py", line 39, in <module>
from pip._vendor.distlib.scripts import ScriptMaker
  File "/opt/agisoft/metashape-pro/python/lib/python3.5/site-packages/pip/_vendor/distlib/scripts.py", line 14, in <module>
from .compat import sysconfig, detect_encoding, ZipFile
  File "/opt/agisoft/metashape-pro/python/lib/python3.5/site-packages/pip/_vendor/distlib/compat.py", line 66, in <module>
from urllib.request import (urlopen, urlretrieve, Request, url2pathname,
ImportError: cannot import name 'HTTPSHandler'

The metashape-pro version is 1.6.3, and I believe I used the correct python
Code: [Select]
$ LD_LIBRARY_PATH=/opt/agisoft/metashape-pro/python/lib /opt/agisoft/metashape-pro/python/bin/python3.5 --version
Python 3.5.2

Any suggestions to resolve this issue would be appreciated.
Title: Re: External python modules not found
Post by: PolarNick on August 07, 2020, 07:43:25 PM
As a workaround you can try to download packages with system python and then install it in bundled python:

1. Install system python 3.5
2. Make empty dir and cd to it (mkdir pip_packages and cd pip_packages)
3. python3.5m -m pip download Pillow
4. wait for downloading all packages (including dependencies)
5. LD_LIBRARY_PATH=python/lib/ python/bin/python3.5m -m pip install --upgrade --no-index --find-links=pip_packages Pillow