-1

using "C:\Program Files\QGIS 2.18\bin\python.exe" for my project interpreter in pycharm and, path variables as : PYTHONHOME = "C:\Program Files\QGIS 2.18\bin" PYTHONPATH = "C:\Program Files\QGIS 2.18\apps\Python27\Lib" when I execute code in pycharm containing PyQt4, it will give me an error (no module named PyQt4) and when i try to install packaging tools via pycharm settings, it will give me another error called"no module named socket"... exact code is written below->

Traceback (most recent call last):
  File "c:\users\ash\appdata\local\temp\tmpodyeojpycharm-management\setuptools-28.8.0\setup.py", line 11, in <module>
    import setuptools
  File "c:\users\ash\appdata\local\temp\tmpodyeojpycharm-management\setuptools-28.8.0\setuptools\__init__.py", line 10, in <module>
    from setuptools.extern.six.moves import filter, filterfalse, map
  File "c:\users\ash\appdata\local\temp\tmpodyeojpycharm-management\setuptools-28.8.0\setuptools\extern\__init__.py", line 1, in <module>
    from pkg_resources.extern import VendorImporter
  File "c:\users\ash\appdata\local\temp\tmpodyeojpycharm-management\setuptools-28.8.0\pkg_resources\__init__.py", line 36, in <module>
    import email.parser
  File "C:\Program Files\QGIS 2.18\apps\Python27\Lib\email\parser.py", line 12, in <module>
    from email.feedparser import FeedParser
  File "C:\Program Files\QGIS 2.18\apps\Python27\Lib\email\feedparser.py", line 27, in <module>
    from email import message
  File "C:\Program Files\QGIS 2.18\apps\Python27\Lib\email\message.py", line 16, in <module>
    import email.charset
  File "C:\Program Files\QGIS 2.18\apps\Python27\Lib\email\charset.py", line 13, in <module>
    import email.base64mime
  File "C:\Program Files\QGIS 2.18\apps\Python27\Lib\email\base64mime.py", line 40, in <module>
    from email.utils import fix_eols
  File "C:\Program Files\QGIS 2.18\apps\Python27\Lib\email\utils.py", line 28, in <module>
    import socket
  File "C:\Program Files\QGIS 2.18\apps\Python27\Lib\socket.py", line 47, in <module>
    import _socket
ImportError: No module named _socket

how can I solve that?

  • i didn't understand all of your problem, but first, qgis comes with it's own python, so whatever ide you use, you must use the python, that comes with qgis. PYTHONPATH and PYTHONHOME must be set to that python version, normally done through the batch files you start qgis with. – Andreas Müller Aug 30 '17 at 13:08
  • Thanks Andreas. if i set my pycharm and both PATHs to qgis python(which I believe is 2.7.5 in my case) pycharm do not recognise PyQt4 "no module named PyQt4". and if I want to install packaging tools from pycharm it says "ImportError: No module named _socket" how can i get rid of this problem? – Afshin Salehi Aug 30 '17 at 21:49
  • for additional information please visit: gis.stackexchange.com/questions/256023/… – Afshin Salehi Sep 21 '17 at 15:57
1

found what the problem was! for using qgis python version in windows,

set PYTHONHOME = C:\Program Files\QGIS 2.18\apps\Python27

And

set PYTHONPATH to where the packaging is:

PYTHONPATH = C:\Program Files\QGIS 2.18\apps\Python27\Lib

***and most important is the system variable PATH which should point to both directories above as well as where the scripts are and where the python.exe is so:

add PATH (add by ; as front) = ;%PYTHONHOME%;%PYTHONHOME%\Scripts;C:\Program Files\QGIS 2.18\bin;%PATH%

to your current path.

So with every IDE(pycharm, notepad++, etc...) that you use, everything should be fine now...

for adding modules like "exifread" to your current site-packaging(PyQt4, numpy and so on) you can read it here:

http://quantumofgis.blogspot.be/2014/11/qgis-standalone-and-python-modules.html

  • Gratulation! You may also want to read this: planet.qgis.org/planet/tag/pycharm By the way: don't change the variables in your standard windows environment, because other programs may use a different python installation. Inside the OSGEO4W-World these variables shoud be set inside the batch files, that start a program (e.g. pycharm)! – Andreas Müller Aug 31 '17 at 8:44
  • Thanks, Andreas, yes I don't have to change environment variables as you said. it gave me a serious problem which I wrote in another topic... – Afshin Salehi Sep 21 '17 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.