I am trying to access GRASS modules and functions from within a python IDE. (I am using WingIDE)
My googling search tells me it can be done (i think) but I cant find any clear instructions on how to do it. Is anyone able to give me some clear instructions on what I need to do?
Simply typing this line of code does not work. I dont think it is locating the grass modules. I have arcgis 10.1
import sys
import grass.script as grass
The ultimate goal is to be able to use both the argis toolbox and GRASS tools.
Anyway hopefully it is something easy and obvious to someone out there,
Any help would be great,
Cheers,
Dan
Wing IDE may be picking up another Python installation as the default, rather than the one where you have grass installed. You can check that in Show Python Environment in the Source menu, and configure it in Project Properties in the Project menu (or Configure Python dialog in Wing 101). If for some reason you didn't install grass into Python but have it in a separate place, you may need to configure Python Path as well or instead.
Once that's done, the script should be able to run in the debugger and successfully import the module (or you can also do this in the Python Shell).
If this doesn't help please let me know or email support#wingware.com.
Beyond #Wingware's important point, and presuming that your "grass.script" is a python module, your PYTHONPATH needs to include the directory that contains "grass.script" for the python interpreter to be able to find/import the desired script. You should be able to set this via the IDE or from the OS prior to starting the IDE.
Related
I would like to use PyCharm Community Edition 2020.1.2 x64 on Windows 10 as IDE for writing QGIS plugins. I need to base on old version - QGIS 2.18, so I need python 2.7, qt4, and also core modules from QGIS 2.18. I downloaded QGIS 2.18 from official site. It provides a ready to use python environment as .bat script, that sets all needed python paths. So I used path D:\Program Files\QGIS 2.18\bin\python-qgis-ltr.bat to set main python interpreter for my project.
After that I was able to run python console in PyCharm, import all QGIS modules, and any classes from QGIS standard collection like QgsFeature, QgsVectorLayer etc. Everything was fine untill I tried to import this classes from PyCharm editor in .py file as from qgis.core import QgsFeature. In editor PyCharm sees the package qgis.core and I'm able to import it, but PyCharm's code completion inside the module sees only classes that are saved in D:\Program Files\QGIS 2.18\apps\qgis-ltr\python\qgis\core\__init__.py e.g. QgsEditError class, but all standard QGIS class underlines on red.
Python console ran on exactly the same interpreter see the same sources as are visible in "External Libraries" tab in PyCharm, so command:
qgis.core.__path__ returns ['D:\\Program Files\\QGIS 2.18\\apps\\qgis-ltr\\python\\qgis\\core'],
qgis.core.__file__ returns 'D:\\Program Files\\QGIS 2.18\\apps\\qgis-ltr\\python\\qgis\\core\\__init__.pyc,
dir(qgis.core) returns full list of QGIS standard core classes.
If I run the .py script, in which PyCharm's code validator is showing incorrect import object by red underline, the script is executed without any error and I can easly print the imported QgsFeature object. Why my PyCharm's editor see different content of qgis.core module then console ran also from IDE on exactly the same interpreter?
Allow me to qualify myself. I lost interest for adventures and trail blazing in computing some time ago. I won some big battles and lost some too. And I unnecessary wasted a lot of time that could have been better spent. Nowadays, I just wait a reasonable period of time before upgrading anything, and wait a spell before downloading the newest anything, and pretty much avoid trying to do things outside a conventional path.
So your post got me curious and I looked around some. I found very little information about PyCharm being used building QGIS plugins. That pretty much tells me all I want to know: that it's not real common for PyCharm to be used in building QGIS plugins.
But there was quite abit of information about building QGIS plugins with python. There's even a QGIS Tutorial & Tips on the subject. QGIS suggests using the Qt Creator and further goes on to say that QGIS itself is written using the QT framework. "For plugin development, we use an application called Qt Creator."
If you overcome your current predicament I'd like to hear how you accomplished it.
For what it's worth, here's the link to the QGIS Tutorials & Tips.
https://www.qgistutorials.com/en/docs/building_a_python_plugin.html
Finally, the problem solved itself. It was something wrong with building a binary skeletons of C++ libraries, what PyCharm does every time the application is launched. My PyCharm didn't want to do it and I found many similar problems with other libraries (e.g. Qt) that people were struggling with. After two days my PyCharm just fixed itself and created all needed binary skeletons for my QGIS libraries.
I have a problem with Python and lettuce.
I already install the pip and lettuce in Python 2.7, and I'm trying to create a .features file and a .py file for the steps. The problem is that when I put the line from lettuce import * I have an error that says:
"Unresolved reference lettuce..." and then: "this inspection detects names that should resolved but don't. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Top-level and class-level items are supported better than instance items".
I really donĀ“t know how to fix this problem. Can anyone can help me please?
I just found the problem. What I did, just in case anyone has the same problem is:
In my PyCharm project:
press Ctrl+Alt+s to open the settings
on the left column, select Project Interpreter
on the top right there is a list of python binaries found on your system, pick the right one
eventually click the + button to install additional python modules
validate
Just in case you are not able to add an other module (that happened to me as well) you can change the project interpreter.
Hope this works!
I have been fumbling around between IDLE/PythonWin and even Aptana Studio 3 trying to get some consistency regarding importing modules. The modules I have been using lately are wx from wxPython and the arcpy module. IDLE will let me import arcpy, but not wx. PythonWin will let me import wx, but not arcpy.
When I do sys.executable in IDLE I get "C:\Python27\ArcGIS10.1\Lib\site-packages\pythonwin\Pythonwin.exe"
When I do sys.executable in PythonWin I get "C:\Python27\pythonw.exe"
Additionally, I am wondering if I am using different interpreters, how to set them all to the same one, and which one to use.
I have been learning and using Python for a little over half a year now and am at the point where I would really like to have these kinds of issues under control.
edit: lesson learned years later: use pycharm and let it keep your environments separate for you! lol
The problem is that ArcGIS comes with its own specific Python bundled with the software and you have installed a normal distribution into "C:\Python27\". I would try removing the latter and reinstalling wxPython. I'm guessing this IDLE of which you speak is actually embedded in ArcGIS rather than being the normal IDLE.
To be more clear, when you originally installed wx, it saw the Python in "C:\Python27\" and installed in that location. If you can't get wx to install to the GIS location, there may be a way to fake it by just copying the wx folder from C:\Python27\ and putting it in ArcGIS. They should both be in something like "C:\Python27\Lib\site-packages\wx-2.9.3-msw" (depending on version) and there's also a wx.pth file you'll need to copy from ""C:\Python27\Lib\site-packages" to the same basic location in the GIS directory.
EDIT: I also found the following links that might address your issue:
http://www.scoop.it/t/arcpy/p/1759717424/custom-wxpython-gui-s-an-approach-for-arcgis-10-1-arcgis-resource-center
http://forums.arcgis.com/threads/41809-wxPython-hooked-to-arcmap
wxPython and ARCGIS
It sounds like you have to add wxPython as an add-in.
I have had trouble setting up the pycharm ide on my macosx10.7 with python3..
I have scoured every resource available and tried hundreds of approaches, at this point I must accept my incompetence and seek help via this channel.
In my research, I notice a lack of ground-up explanations on python integration into macosx and how to configure pycharm to import modules, run code within the editor, etc. If i ever solve this I will make a very detailed tutorial.
I have imported python3 successfully, it looks like it is linked appropriately from /sys/lib/frameworks to /usr/lib ...etc -- version control is working just fine.
I think my issue is either in setting environmental variables (tried the program to fix this and tried macports) and in the script needed to execute. it will catch errors throughout but final product does not run in python and returns printout of :
/Library/Frameworks/Python.framework/Versions/3.2/bin/python3.2 /Users/anon/Desktop/pythonpractice/Py_Ex/classes.py
Process finished with exit code 0
i really need to get this configuration sound for my python programming class. please help (I've been through every line of pycharm website) .. preferably is there a way to map it via terminal? thanks for anyone who took the time to read this.
Summary of the discussion above:
Python 3.2.2 installation was broken on this Mac, installing ActiveState Python 3.2.2 from scratch and configuring it in PyCharm has fixed the problem.
Python path to be used in PyCharm settings: /Library/Frameworks/Python.framework/Versions/3.2/bin/python3
Incompatible third-party plug-ins may break PyCharm, uninstall/disable them in Preferences | Plugins.
Ensure the latest PyCharm version is installed.
User's code depends on the graphics.py module which was not in the project or in the PYTHONPATH. Putting it into the project has solved the problem.
Most likely the wrong Run/Debug configuration was used in PyCharm, the easiest way to run or debug such scripts is by using the editor context menu Run and Debug actions. PyCharm creates the configuration automatically and debugging works fine as shown of the screenshot:
If one wants to configure and debug it, he can use the code.zip file to get started.
Sorry for the comments mess above, but it was not possible to move it into chat as user had only 1 reputation point, hence not able to use the chat feature of StackOverflow.
I am working with python plugins for QGIS . I am done with my one of my .py file using python 2.5 and pyqt4. It is just help file for QGIS, which I changed. I wanted to in-cooperate the same in QGIS. I installed QGIS 1.7.1.
I know it to be done through python plugins. But how to go about it?
where to copy my file, so that it will get open from QGIS?
QGIS already has that page(help file), I need to change it.
help me out.
If you're creating a QGIS plugin in Python, you may want to place it in your .qgis/python/plugins folder. Actually, you should create a subfolder below that. But that's not all, your code has to provide certain functions in order to get hooked up properly into QGIS. http://qgis.org/pyqgis-cookbook/plugins.html#plugins provides detailed information about that. Once your Python plugin is complete and located in the correct location, you'll have to enable it in the QGIS Plugin Manager (choose Plugins/Manage Plugins... from the manu). I'm not sure if your question is about creating QGIS Python Plugins or about replacing QGIS menu items via Python - could you clarify this? Are there any error messages for the things that are not working? Could you post your code (or relevant parts of it) for review (this might speed up the process of finding a solution)?