Forum

Author Topic: Build-in python can not create venv on Windows  (Read 5123 times)

howcanoewang

  • Newbie
  • *
  • Posts: 14
    • View Profile
Build-in python can not create venv on Windows
« on: February 22, 2025, 05:23:46 AM »
Hi, I am developing a plugin for metashape, in order to avoid dependencies conflict for Metashape build-in python, my plugin will generate a venv first when install dependencies in that virtual environment and execute in that venv later.

The following command to create venv works good on Linux

Code: [Select]
/opt/agisoft/metashape-pro/python/bin/python3.9 -m venv /path/to/myvenv   

However, when executing the same command on Windows (tested on 2.1.4 & 2.2.1), it gave the following error:

Code: [Select]
C:\Apps\Agisoft\Metashape Pro\python>python.exe -m venv /path/to/myvenv
Unable to copy 'C:\\Apps\\Agisoft\\Metashape Pro\\python\\venvlauncher.exe'
Error: [WinError 2] The system can't find the files.

It seems python official website of the same version works perfectly, without venvlauncher.exe in the python root folder.

Could you please check if it possible to fix the problem?

PolarNick

  • Full Member
  • ***
  • Posts: 112
    • View Profile
Re: Build-in python can not create venv on Windows
« Reply #1 on: March 03, 2025, 04:59:01 PM »
Perhaps using the Metashape Python Wheel would work for you?

To do this, simply download the .whl file (see the Python 3 Module at https://www.agisoft.com/downloads/installer/) and install it in any Python or a virtual environment created based on the downloaded standard Python (it’s most reliable to use the same Python version that Metashape uses—i.e., Python 3.9).


howcanoewang

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Build-in python can not create venv on Windows
« Reply #2 on: March 06, 2025, 06:01:53 PM »
Perhaps using the Metashape Python Wheel would work for you?

To do this, simply download the .whl file (see the Python 3 Module at https://www.agisoft.com/downloads/installer/) and install it in any Python or a virtual environment created based on the downloaded standard Python (it’s most reliable to use the same Python version that Metashape uses—i.e., Python 3.9).

Thanks for your kindly suggestion, it could be a solution but may not so user friendly. I would not expect my plugin ask user manually install specified python on their side.

Several days before, I solved this problem by using
Code: [Select]
pip install uv into build-in python as the venv creator.
https://github.com/UTokyo-FieldPhenomics-Lab/EasyAMS/blob/19c57f1c7713f339f0bfa29b5b0ed0b2c631c799/installer.py#L163-L211

However, after reading through some official demos these days, I found that Metashape natively supports using isolated site-packages to avoid dependency conflicts.
The examples is here: https://github.com/agisoft-llc/metashape-scripts/blob/master/src/align_model_to_model.py

I decided to modify my implementation based on this solution.

Thanks again for your kindly reply, and hoping my project can help someone met the same problem