Problems importing grass.script into PyDev - python

I am trying to do grass scripting in Eclipse and i follow the instructions outlined in this page. I think i have everything configured however when i try to import grass.script i get the following message:
Traceback (most recent call last):
File "/home/nesic/Desktop/grass_dev/Simulacije/test.py", line 6, in <module>
import grass.script as grass
File "/usr/lib/grass64/etc/python/grass/script/__init__.py", line 1, in <module>
from core import *
File "/usr/lib/grass64/etc/python/grass/script/core.py", line 38, in <module>
gettext.install('grasslibs', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
File "/usr/local/lib/python2.6/posixpath.py", line 67, in join
elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'
What am I doing wrong?

os.getenv("GISBASE") most likely returns None, because the envorinment variable GISBASE is not set. That then leads to the AttributeError: 'NoneType' object has no attribute 'endswith' you're seeing.
Try setting GISBASE according to http://grass.osgeo.org/grass70/manuals/variables.html:
GISBASE
directory where GRASS lives. This is set automatically by the startup script.
(BTW, if you don't know about it already, there's also gis.stackexchange.org)

Related

AttributeError module 'select' has no attribute 'poll'

May I ask for some help? I am attempting to clone an existing GitHub project and am struggling to identify what I could be doing wrong. The project is a pluggable SXM music player written in Python ( https://github.com/AngellusMortis/sxm-player), that I've cloned and attempted to run through Visual Studio Code (v1.65.2). Upon executing the project, the code returns an error - "Exception has occurred: AttributeError module 'select' has no attribute 'poll'". Little doubt that I must be doing something incorrectly - but to this point, I haven't been able to identify what I need to do differently to get it to run properly. My sincerest apologies for needing to ask this probably simple question on this forum, but I know that this would be the place to find the experience to get this package up and running and any assistance would be greatly appreciated.
Here is the traceback for the error message:
File "C:\GitHub\sxm-player\sxm_player\utils.py", line 173, in FFmpeg
_stderr_poll: Optional[select.poll] = None
File "C:\GitHub\sxm-player\sxm_player\utils.py", line 169, in <module>
class FFmpeg:
File "C:\GitHub\sxm-player\sxm_player\runner.py", line 9, in <module>
from sxm_player.utils import configure_root_logger
File "C:\GitHub\sxm-player\sxm_player\handlers.py", line 6, in <module>
from sxm_player.runner import Runner, Worker
File "C:\GitHub\sxm-player\sxm_player\cli.py", line 23, in <module>
from sxm_player import handlers
File "C:\GitHub\sxm-player\sxm_player\__main__.py", line 3, in <module>
from sxm_player.cli import main

My python code runs once, but I get an error when I run it twice

I have a little python script that checks my current IPv4 DNS Server address. It's working just fine. I use the wmi package.
Now: I use this script in Kodi. And first time it runs, it runs perfectly. But the second time I get a weird error.
Why does my code work the first time, but not the following attempts?
Hope you guys can help me. I'm lost.
my script:
import wmi
nic_configs = wmi.WMI().Win32_NetworkAdapterConfiguration(IPEnabled=True);
nic = nic_configs[0];
dns = nic.DNSServerSearchOrder[0];
the error:
Error Type: <type 'exceptions.AttributeError'>
Error Contents: 'NoneType' object has no attribute 'platform'
Traceback (most recent call last):
File "C:\Python\Lib\site-packages\mytest.py", line 22, in <module>
import wmi
File "C:\Python\Lib\site-packages\wmi.py", line 88, in <module>
from win32com.client import GetObject, Dispatch
File "C:\Python\Lib\site-packages\win32com\__init__.py", line 6, in <module>
import pythoncom
File "C:\Python\Lib\site-packages\pythoncom.py", line 3, in <module>
pywintypes.__import_pywin32_system_module__("pythoncom", globals())
File "C:\Python\Lib\site-packages\pywintypes.py", line 20, in __import_pywin32_system_module__
if not sys.platform.startswith("win32"):
AttributeError: 'NoneType' object has no attribute 'platform'
-->End of Python script error report<--

can't import ethjsonrpc in python3.6 , ubuntu

when importing ethjsonrpc It throws an error as below:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/ethjsonrpc/__init__.py", line 1, in <module>
from ethjsonrpc.client import (EthJsonRpc, ParityEthJsonRpc,
File "/usr/local/lib/python3.6/site-packages/ethjsonrpc/client.py", line 7, in <module>
from ethereum import utils
File "/usr/local/lib/python3.6/site-packages/ethereum/utils.py", line 103, in <module>
assert sha3('').encode('hex') == 'c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'
AttributeError: 'bytes' object has no attribute 'encode'
This is an issue with ethjsonrpc as can be seen on the github issue page. The proposed fix is to just comment the line 103 in /usr/local/lib/python3.6/site-packages/ethereum/utils.py
Might be a good idea to switch to using this module with python2 instead in case more errors appear that are caused by version differences.

AttributeError: 'module' object has no attribute 'Template'

I'm using MacOs with the PyCharm environment, and my project is set to use Python 2.7.10. Now, I have on the first line of my module the line:
import numpy as np
When I try to run my code, I get the following error:
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /{path to file}/numpy_exercise.py
Traceback (most recent call last):
File "/{path to file}/numpy_exercise.py", line 1, in module>
import numpy as np
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/__init__.py", line 169, in module>
from . import polynomial
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/polynomial/__init__.py", line 20, in module>
from .polynomial import Polynomial
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/polynomial/polynomial.py", line 68, in module>
from .polytemplate import polytemplate
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/polynomial/polytemplate.py", line 17, in module>
polytemplate = string.Template(''' AttributeError: 'module' object has no attribute 'Template'
(note that "module>" was actually in brackets from both sides but because it gets omitted that way I daleted the first bracket so you can see it)
Though in Python 3 it does not happens to me. I looked on the web but couldn't find anything. I have no clue of why this is happening. I'd be glad to get some of your help!
Thank you guys!

Python AttributeError: 'module' object has no attribute 'name'

Trying to setup client Python script in my Windows system and finally i got stuck up with the below error, Tried in the Google and myself of about 4 hrs. But not able find out the solution. Since i am very new to the Python, I could not able to find out the solution.
Please have a look at below code and its error, So you may have solution for me,
Error:
C:\Python26>python C:\xampp\htdocs\cequel-dev\mbtools\main_inject.py
Traceback (most recent call last):
File "C:\xampp\htdocs\cequel-dev\mbtools\main_inject.py", line 12, in <module>
import injectdir
File "C:\xampp\htdocs\cequel-dev\mbtools\injectdir\__init__.py", line 10, in <module>
import action
File "C:\xampp\htdocs\cequel-dev\mbtools\injectdir\action\__init__.py", line 1, in <module>
from command import list
File "C:\xampp\htdocs\cequel-dev\mbtools\injectdir\action\command.py", line 28, in <module>
action_list[action.name]=action
AttributeError: 'module' object has no attribute 'name'
Code: (Line no: 19 to 28)
try:
action_list={}
for file in filenames:
if file.endswith('.py') and file != '__init__.py' and file != 'command.py':
#Import the file as a module action_imp
exec "import {0} as action_imp".format(file[0:-3])
#Get the action object from action_imp. Name is a required method for all actions
action=action_imp
#Put the file name in file_name
action.file_name=file[0:-3]
action_list[action.name]=action
except:
This seems like a array attribute error. So i have tried with if condition, But no luck so far.
So i have stuck with the last line ( "action_list[action.name]=action" ). Please let me know if you have any suggestions or any quick solution to suppress the error in the for loop.
Thanks.
As the comment after the exec statement says, every action has to have a name.
Ensure that every file listed in filenames (except __init__.py and command.py) contains a variable name.
Alternatively, you can suppress the error by replacing line 28 with:
try:
action_list[action.name]=action
except AttributeError:
print "Could not register action", action.file_name

Categories