FlatCAM from source with venv and win10

Issue #554 new
nerdunio created an issue

I am trying to install FlatCAM Beta from source on win10.

Because I’m using different versions of Python for my other projects I want to use a virtual environment.

What I did:

  • Had Python 3.9.2 installed on my machine (no WinPython).
  • Download GDAL-3.4.1-cp39-cp39-win_amd64.whl and rasterio-1.2.10-cp39-cp39-win_amd64.whl from https://www.lfd.uci.edu/~gohlke/pythonlibs/.
  • Comment out gdal and rasterio in the requirements.txt.
  • Then on the console:
git clone https://bitbucket.org/marius_stanciu/flatcam_beta.git
cd flatcam_beta
git checkout Beta_8.995

python --version
> Python 3.9.2

python -m venv venv
venv\scripts\activate

(venv) python -m pip install --upgrade pip

(venv) pip install GDAL-3.4.1-cp39-cp39-win_amd64.whl
> Successfully installed GDAL-3.4.1

(venv) pip install rasterio-1.2.10-cp39-cp39-win_amd64.whl
> Successfully installed ... rasterio-1.2.10

(venv) pip install -r requirements.txt
> Successfully installed PyQt6-Qt6-6.2.2 ... webencodings-0.5.1

(venv) python FlatCAM.py
Traceback (most recent call last):
  File "C:\desktop\flatcam_beta\FlatCAM.py", line 8, in <module>
    from app_Main import App
  File "C:\desktop\flatcam_beta\app_Main.py", line 57, in <module>
    from appDatabase import ToolsDB2
  File "C:\desktop\flatcam_beta\appDatabase.py", line 4, in <module>
    from camlib import to_dict
  File "C:\desktop\flatcam_beta\camlib.py", line 43, in <module>
    import rasterio
  File "C:\desktop\flatcam_beta\venv\lib\site-packages\rasterio\__init__.py", line 17, in <module>
    from rasterio._base import gdal_version
ImportError: DLL load failed while importing _base: The specified procedure could not be found.

As Marius pointed out that the version of gdal and rasterio must match I tried other available version of gdal for python 3.9.

  • GDAL‑3.3.3‑cp39‑cp39‑win_amd64.whl
  • GDAL‑3.2.3‑cp39‑cp39‑win_amd64.whl

However, both version of gdal exit the installation with an error status.

Note: I did repeat the same with WinPython 3.9.5 and a virtual environment but the result was the same.

I would appreciate if someone could help me or share his solution with me.

Thanks!

Comments (10)

  1. Marius Stanciu

    Hello Manuel,
    I have attached the file with the GDAL module that I also use together with the latest Rasterio module (v 1.2.10). Try it and write here if it solves the issue.

  2. nerdunio reporter

    Hi Marius,

    Thank you for the file. Unfortunately this does not solve my problem.

    From the output (line 3) it seems that rasterio 1.2.10 requires gdal version 3.4.1. Then in line 14 the previously installed version 3.3.2 of GDAL is uninstalled.

    I assume at line 16 the installer tries to install GDAL 3.4.1 which fails because pip install rasterio would also fail (that’s why we use the prebuild binaries from https://www.lfd.uci.edu/~gohlke/pythonlibs/).

    pip install rasterio-1.2.10-cp39-cp39-win_amd64.whl
    Processing rasterio-1.2.10-cp39-cp39-win_amd64.whl
    Collecting gdal~=3.4.1
      Using cached GDAL-3.4.1.tar.gz (755 kB)
    Collecting click>=4.0
      Using cached click-8.0.3-py3-none-any.whl (97 kB)
    ...
    Collecting pyparsing>=2.1.6
      Using cached pyparsing-3.0.6-py3-none-any.whl (97 kB)
    Using legacy 'setup.py install' for gdal, since package 'wheel' is not installed.
    Installing collected packages: gdal, colorama, click, numpy, cligj, pyparsing, snuggs, affine, certifi, click-plugins, attrs, rasterio
      Attempting uninstall: gdal
        Found existing installation: GDAL 3.3.2
        Uninstalling GDAL-3.3.2:
          Successfully uninstalled GDAL-3.3.2
        Running setup.py install for gdal ... error
        ERROR: Command errored out with exit status 1:
    ...
    

    Now, when I use GDAL 3.4.1 and rasterio 1.2.10 the installation is working but I can’t launch FlatCAM.py.

    I got the example of https://pypi.org/project/rasterio/ working with GDAL version 3.4.1 and rasterio 1.2.10 in a virtual environment. Hence I don’t think that rasterio is the problem.

  3. nerdunio reporter

    I added import rasterio in line 6 of FlatCAM.py to import the package before all other packages. The import worked and now FlatCAM launches.

    However, I can’t open gerber nor excellon files. I assume this due to my configuration.

  4. Marius Stanciu

    Hello Manuel,
    In my experience, Rasterio 1.2.10 require Gdal 3.3.2. It is interesting that you make it work with Gdal 3.4.1 but try to uninstall both rasterio and gdal and install first the Gdal package (because it is a dependency for rasterio, Rasterio needs it) and after that Rasterio.

    Both packages have no impact on opening files (Gerber, Excellon etc) which means you have another issue. Offering more details and the log of the error (you can see a lot of information's in the console and in the TCL Shell (within the app)) is required in order to solve the potential issues.

    I have a PC that have older packages of Gdal and rasterio and I will update them (after first uninstalling them) and write here my experience.

  5. Marius Stanciu

    Ok…. It looks like an upstream bug. Now the Rasterio 1.2.10 package asks specifically for Gdal 3.4.1…. but at the same time it shows the same error you got which is an internal error of Rasterio. It looks like I was doing progressive upgrades and uninstalling left something on system from the older version which make it to work.

    I guess that this issue should be reported on the rasterio git page although I don’t think that they cover wheels generated by a 3rd party. If possible maybe Gohlke should be the one to notify…

    I’ll keep looking on it.

  6. Marius Stanciu

    In any case the solution I found is to use older packages (no longer available on Gohlke’s page) for both Rasterio and Gdal.
    I will attach them to your first post. I’ll try your fix too and see if I can find something to fix this dependency.

  7. nerdunio reporter

    Hello Marius,

    If I repeat the setps of the initial issue with the two provided files everything works fine. ✅

    Thank you for your detailed explanation and great support!

  8. Marius Stanciu

    Hi,

    It’s crazy. It also works with the import rasterio added somewhere in the App_main file and with Rasterio 1.2.10 and GDal 3.4..1 but have to be done before the imports of Shapely yet doing that then Shapely is broken and require to be downgraded from current version 1.8.0 to 1.7.0 in order to be able to open files to open files and so on.

    All this mess is between the Shapely (which uses GDAL) and Rasterio (which also uses GDAL). And If I have to choose between Rasterio and Shapely then I will have to ditch Rasterio because Shapely is essential and Rasterio helps only with a feature: Import Image Plugin….

  9. Log in to comment