Python Arcpy: Non-ASCII character in library import - python

I was debugging a basic GIS python script, when I randomly(?) got this error:
Traceback (most recent call last):
File "<module1>", line 13, in <module>
import arcpy
File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\__init__.py", line 25, in <module>
from arcpy.toolbox import *
File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\toolbox.py", line 371, in <module>
from .management import Graph, GraphTemplate
File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\management.py", line 5694
SyntaxError: Non-ASCII character '\xc2' in file C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\management.py on line 5695, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
Tried just running import arcpy and the same error popped up. So far here's what I tried:
Ran from Pyscripter and cmd.
Restarted my computer a couple times.
Opened that management.py file out of curiosity but it's only a couple hundred lines? I'm a GIS/data analyst, not a programmer of any sort, so this realm is beyond what I know.
I'm stumped. Yes, I could reinstall the library, but that's quite involved as this library is a tiny part of a massive software package.

you can have a try add "#encoding: utf-8" in your first row

Add # -*- coding: utf-8 -*- at the top of your script.
Probably the IDE that you are using, use the default encoding set.

Related

Error while attempting to import openai's universe

While importing openai's universe, i get these errors:
Traceback (most recent call last):
File "/Users/calvin/Desktop/universe-test/main.py", line 2, in <module>
import universe
File "/Users/calvin/universe/universe/__init__.py", line 22, in <module>
from universe import error, envs
File "/Users/calvin/universe/universe/envs/__init__.py", line 1, in <module>
import universe.envs.vnc_env
File "/Users/calvin/universe/universe/envs/vnc_env.py", line 11, in <module>
from universe.envs import diagnostics
File "/Users/calvin/universe/universe/envs/diagnostics.py", line 94
async = self.qr_pool.apply_async(self.method, (self._last_img, time.time(), available_at))
^
SyntaxError: invalid syntax
I've tried downloading a different version of gym, reinstalling universe, and nothing works. I have python 3.8.5 64-bit. My operating system is macOS Catalina 10.15.6. Any ideas?
async is now a special keyword, and as such, can't be used as a variable name.
That library appears to be made for Python pre-3.5. I believe your only options are:
Use a older version of Python 3 (async was intrduced in 3.5).
Edit the local copy of the library file to change the name to something else.
Check to see if there are any updates/forks to the library that fix that issue.

Python 2.7 won't load any modules I installed. Will only load native modules that come with Python 2.7

Note: Please don't comment here that Python 2.7 is depreciated. I already know this. I need to get this working first before migrating to 3.x.
On Windows 10, I had installed (and running correctly) both Python 2.7 and Python 3.7. Since I only needed Python 2.7, I uninstalled Python 3.7 (and manually deleted respective packages installed under .\Python37*) as well as the virtual environment directory below. I have no idea if that virtual environment was associated with Python 2.7 or Python 3.7:
C:\Users\MKANET\Envs\MKA.NETT
After I rebooted, to my horror, every time I run a Python 2.7 script, I get a whole bunch of ambiguous traceback errors when trying to import modules I had installed with PIP (for Python 2.7). However, I don't have issues importing the modules like sys, json (packages that come preinstalled with Python 2.7).
When executing script below from Windows command-line:
& C:/Users/MKANET/AppData/Local/Programs/Python/python27/python.exe c:/Users/MKANET/OneDrive/Dev/Projects/Python/test2.py
...I get a bunch of ambiguous traceback errors:.
Traceback (most recent call last):
File "c:/Users/MKANET/OneDrive/Dev/Projects/Python/test2.py", line 3, in <module>
from pypsexec.client import Client
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\pypsexec\client.py", line 8, in <module>
from smbprotocol.connection import Connection, NtStatus
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\smbprotocol\connection.py", line 33, in <module>
from cryptography.hazmat.primitives.ciphers import (
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\cryptography\hazmat\primitives\ciphers\aead.py", line 10, in <module>
from cryptography.hazmat.backends.openssl import aead
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\cryptography\hazmat\backends\openssl\__init__.py", line 7, in <module>
from cryptography.hazmat.backends.openssl.backend import backend
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\cryptography\hazmat\backends\openssl\backend.py", line 16, in <module>
from cryptography import utils, x509
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\cryptography\x509\__init__.py", line 8, in <module>
from cryptography.x509.base import (
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\cryptography\x509\base.py", line 18, in <module>
from cryptography.x509.extensions import Extension, ExtensionType
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\cryptography\x509\extensions.py", line 26, in <module>
from cryptography.x509.general_name import GeneralName, IPAddress, OtherName
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\cryptography\x509\general_name.py", line 10, in <module>
from email.utils import parseaddr
File "c:\Users\MKANET\OneDrive\Dev\Projects\Python\email.py", line 11, in <module>
obj = win32com.client.Dispatch("Outlook.Application")
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)
UPDATE HUGE CLUE:
This is ONLY happens when executing scripts in the below folder:
C:\Users\Michael\OneDrive\Dev\Projects\Python
If I execute a script in any other folder on my C: Drive, modules load perfectly without errors. I don't know what's different about this folder that causes my modules not load. Maybe, there's a file in this folder that causing this?
Since this issue was limited only to scripts inside the below directory:
C:\Users\Michael\OneDrive\Dev\Projects\Python
I was able to narrow the issue down to a file called, email.py. If I tried to import a module for example, requests; for some odd reason an email.pyc would get created; followed by the import module errors. All I did was rename email.py to mail.py.. and, this whole issue finally stopped.
I have no idea why Python 2.7 is sensitive to that file name, but changing it to something else resolved the issue for me. Maybe, someone could comment on why the file name breaks things; especially when I had a __init__.py in the same directory to import another module.

I can't make anaconda work on windows by importing pandas

I am new to Python and am trying to use anaconda to do some data analysis. I am using Python 3.6.2 along with the geany text editor.
First, I'm trying to execute a file call panda.py which only contains import pandas as dp.
When I configure geany with a working directory of C:\Users\Anaconda3\python, I get the following error:
Traceback (most recent call last):
File "panda.py", line 1, in <module>
import pandas as dp
File "C:\Users\Anaconda3\lib\site-packages\pandas\__init__.py", line 13, in <module>
__import__(dependency)
File "C:\Users\Anaconda3\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\Users\Anaconda3\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Users\Anaconda3\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Users\Anaconda3\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Users\Anaconda3\lib\site-packages\numpy\core\__init__.py", line 35, in <module>
from . import _internal # for freeze programs
File "C:\Users\Anaconda3\lib\site-packages\numpy\core\_internal.py", line 18, in <module>
from .numerictypes import object_
File "C:\Users\Anaconda3\lib\site-packages\numpy\core\numerictypes.py", line 962, in <module>
_register_types()
File "C:\Users\Anaconda3\lib\site-packages\numpy\core\numerictypes.py", line 958, in _register_types
numbers.Integral.register(integer)
AttributeError: module 'numbers' has no attribute 'Integral'
The same error also occurs when I enter the following at the command prompt:
C:\Users\Anaconda3\python.exe C:\Users\Documents\python_work\panda.py
However, if I execute C:\Users\David\Anaconda3\python.exe and then enter import pandas as dp in the REPL, it appears to load without error.
Any idea how I can fix this so I can use anaconda with geany?
[SOLVED] John below ask if I had a file called numbers.py in my directory which made me realize I named an exercise I previously did as numbers.py. Once I removed it, the error went away (I tested it further by adding a file with the name again and the error returned).
I'm new to the stack over flow community. Let me know if there's anything else I need to do to close out this question.
Also thanks to chb for the edits to my original question the format looks much easier to read.
Disclaimer: python on windows is not something I know about
You know that C:\Users\David\Anaconda3\python.exe when run standalone knows how to import pandas, so your setup is fine - you have everything installed that you need, and in the correct locations.
Given that, you can look at two issues: gearny setup, and general setup. I noticed that python and pandas is installed under C:\Users\Anaconda3, while your program is under C:\Users\Documents\python_work, and we also have C:\Users\David - could it be permissions issues?

SublimeREPL on Sublime Text 3 not importing Python 2.7 modules

I have been trying to configure SublimeText 3 to run SublimeREPL, setting everything so it runs as IDLE, or PyCharm IDE, but, after trying different options I checked in SO, it keeps returning:
>>> import pandas
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named pandas
>>> import os
>>> os.environ['PYTHONPATH']
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/UserDict.py", line 23, in __getitem__
raise KeyError(key)
KeyError: 'PYTHONPATH'
I have tried editing the SublimeREPL.sublime-settings file with the default extend path file you can see at the FAQ site of SublimeREPL, but still does not work.
Does anyone know how this could be solved?
I don't know if this is the problem for you, but I was getting the exact same error and learned that by opening sublime text from the command line (e.g. 'subl .' to open the directory, once you have that shortcut set up) you get one PATH- and if you open sublime text from Spotlight Search you get another PATH. Try opening sublime text from the command line once you've confirmed you can import pandas in an interactive command line session and hopefully it will work.

Why does python say it does not have the file in the directory when there is the file in the directory?

I am using python, and I am running the script that use the file in the same directory, but it keeps giving me the error saying that there is no such file.
I am using that script file as a module to enable my other script file, by the way. The file I am using as a module is from the github project : https://github.com/nik0spapp/unsupervised_sentiment (unsupervised sentiment analysis)
Traceback (most recent call last):
File "sentiment_analysis.py", line 21, in <module>
import sentiment as unsupervised_sentiment
File "/Users/chlee021690/Desktop/Programming/Python/Recommender System/unsupervised_sentiment/sentiment.py", line 20, in <module>
from hp_classifiers import HpObj, HpSubj
File "/Users/chlee021690/Desktop/Programming/Python/Recommender System/unsupervised_sentiment/hp_classifiers.py", line 16, in <module>
from lexicon import Lexicon
File "/Users/chlee021690/Desktop/Programming/Python/Recommender System/unsupervised_sentiment/lexicon.py", line 17, in <module>
from datasets.emoticons_patch import patch_emoticons
File "/Users/chlee021690/Desktop/Programming/Python/Recommender System/unsupervised_sentiment/datasets/emoticons_patch.py", line 23, in <module>
emoticons_file = open("emoticons.data","r")
IOError: [Errno 2] No such file or directory: 'emoticons.data'
Any help would be the best to me as of now. Thanks!
It's possible when using relative paths instead of absolute paths in your programs that your code is looking for a file (like "emoticons.data") in the directory of the executing program (in this case, the script, NOT the module.) I would first try changing all file-paths to absolute paths in the program, or put the "emoticons.data" in your executing directory.
There is a discrepancy between your error (emoticons_file = open("emoticons.data","r")) and the source code you reference (unsupervised_sentiment/datasets/emoticons_patch.py:23 is emoticons_file = open("datasets/emoticons.data","r")). but the basic problem is the same. The module attempts to open the file using a relative path name, which only works if you are executing from the project's directory.
If you update to the code I found in the repo, you must cd to /Users/chlee021690/Desktop/Programming/Python/Recommender System/unsupervised_sentiment/ to run it.
To me, this is broken and the project maintainers should fix it.

Categories

Resources