简体   繁体   English

无法在 python 应用程序上导入 qgis package?

[英]Cannot import qgis package on python app?

I've a little issue on my python script.我的 python 脚本有一点问题。 I want to import qgis.core to use qgis function in my script but I can't import this package.我想导入 qgis.core 以在我的脚本中使用 qgis function,但我无法导入这个 package。 I work on python virtual environment with python 3.7 and Qgis work with python 3.7 too.我使用 python 3.7 和 Qgis 使用 python 3.7 在 python 虚拟环境中工作。 When I run import qgis.core I obtain this answer:当我运行import qgis.core我得到这个答案:

No module named 'qgis'

This is normal because I can't install it with conda/pip install.这是正常的,因为我无法使用 conda/pip install 安装它。 In my conda shell when I run conda install qgis.core , I have:在我运行conda install qgis.core时,在我的 conda shell 中,我有:

PackagesNotFoundError: The following packages are not available from current channels:

  - qgis.core

Any idea to help me please?有什么想法可以帮助我吗? Thanks.谢谢。

  1. First, for this kind of package like others (TensorFlow, geopandas, gdal, etc) it's important to create a new python environment to install this special code.首先,对于这种 package 和其他(TensorFlow、geopandas、gdal 等)一样,创建一个新的 python 环境来安装这个特殊代码很重要。 I do recommend it.我推荐它。 You can create it in Anaconda Navigator.您可以在 Anaconda Navigator 中创建它。 Click on Environments in Anaconda Navigator (see the picture below).单击 Anaconda 导航器中的环境(见下图)。 In this option, you can choose the python version and the name of your new env.在此选项中,您可以选择 python 版本和新环境的名称。 After that, click on Home in Anaconda Navigator (Figura below) and Install the Spyder for your new environment.之后,单击 Anaconda Navigator 中的 Home(下图)并为您的新环境安装 Spyder。 It can be done in Anaconda Navigator.它可以在 Anaconda Navigator 中完成。

在此处输入图像描述

  1. Second.第二。

In anaconda prompt activate your_new_env (conda activate your_new_env)在 anaconda 提示激活 your_new_env (conda activate your_new_env)

Install qgis ( conda install -c conda-forge qgis)安装 qgis ( conda install -c conda-forge qgis)

  1. Go to Anaconda Navigator, Choose your_new_env in Home Applications on: then open spyder. Go 到 Anaconda 导航器,在 Home Applications on 中选择 your_new_env:然后打开 spyder。 Open spyder.打开间谍。

  2. Try to import qgis尝试导入qgis

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM