I am not sure why I get an AttributeError: module 'graphviz.backend' has no attribute 'ENCODING' when I tried to export regression tree to graphviz. I tried re-installing graphviz and sklearn but it doesn't solve the problem. Appreciate any advice on this.
AttributeError Traceback (most recent call last)
<ipython-input-4-9d9e0becf9b6> in <module>
3 # graphviz is the drawing tool
4 from sklearn.tree import export_graphviz
----> 5 import graphviz
6 dot_data = export_graphviz(
7 model,
C:\ProgramData\Anaconda3\lib\site-packages\graphviz\__init__.py in <module>
25 """
26
---> 27 from .dot import Graph, Digraph
28 from .files import Source
29 from .lang import escape, nohtml
C:\ProgramData\Anaconda3\lib\site-packages\graphviz\dot.py in <module>
30
31 from . import backend
---> 32 from . import files
33 from . import lang
34
C:\ProgramData\Anaconda3\lib\site-packages\graphviz\files.py in <module>
20
21
---> 22 class Base(object):
23
24 _engine = 'dot'
C:\ProgramData\Anaconda3\lib\site-packages\graphviz\files.py in Base()
26 _format = 'pdf'
27
---> 28 _encoding = backend.ENCODING
29
30 #property
AttributeError: module 'graphviz.backend' has no attribute 'ENCODING'
I had a similar issue when using pipdeptree. It would seem that there was a very recent change to graphviz, intended to obfuscate its internals. Quoting the module author's reply in issue #149 (a similar issue with backend.FORMATS):
Submodules of graphviz are not part of the public API (cf. https://graphviz.readthedocs.io/en/stable/api.html). Please stick to the documented interface and use graphviz.FORMATS, see https://graphviz.readthedocs.io/en/stable/api.html#graphviz.FORMATS).
In the short term, you could downgrade your graphviz module… it looks like 0.18 was the last tag before the submodules were made opaque.
Moving forward, you may wish to create an issue and/or pull request against the sklearn-pandas repository, to replace graphviz.backend.FORMATS with graphviz.FORMATS, or even just cap its graphviz dependency at 0.18.
I had the same issue and I am very new to Python/conda world, so this might help newbies like me...
I downloaded graphviz 0.19.1 from:
https://pypi.org/project/graphviz/#files
Source Distribution: graphviz-0.19.1.zip (247.8 kB view hashes)
download link
and replaced graphviz folder with this version in "C:\Users\Nino\anaconda3\Lib\site-packages" (will be different for you) and rename it so that name is again graphviz.
"C:\Users\Nino\anaconda3\Lib\site-packages\graphviz"
I have met same problem! The most voted answer works for me! And paste the code to forceably downgrade the graphviz.
pip install --force-reinstall graphviz==0.18
I had the same error with python-graphviz==0.16. OP did not include a version number, but it looks like the line numbers in the traceback match with v0.16.
Note that the traceback shows the error to be inside the python-graphviz package, so it's more likely that it's an issue with a dependency.
With python-graphviz==0.19 I don't get the import error.
On a side note: Versions shown by conda list or pip list can be misleading. In case of doubt check the content of the __init__.py.
I solved this issue in a different way:
Open graphviz file on my PC through following path (Path may differ)
"C:\Users\Anoop\anaconda3\Lib\site-packages\graphviz\backend"
Copy the encoding.py file from here
Paste this file in the backend
"C:\Users\Anoop\anaconda3\Lib\site-packages\graphviz\backend"
Problem solved
In my case, it seems that the class Base in the "C:\ProgramData\Anaconda3\lib\site-packages\graphviz\files.py" takes the 'backend folder' instead of the 'backend.py' on init.
quick solve:
go to "C:\ProgramData\Anaconda3\lib\site-packages\graphviz" and rename the 'backend folder' to something else.
PS: since I didn't check the whole code, it may then cause another dependency problem.
Thanks! ver0.2 was trouble some and this error disappear after downgrading it with ver 0.19
Related
I would need to load nltk 'words' data from local disk. In the notebook my code looks like the following,
import nltk
nltk.data.path.append("/data") # Setting path here
nltk.corpus.words.words()
But I am getting error as follows,
LookupError Traceback (most recent call last)
/anaconda3/lib/python3.8/site-packages/nltk/corpus/util.py in __load(self)
83 try:
---> 84 root = nltk.data.find(f"{self.subdir}/{zip_name}")
85 except LookupError:
/anaconda3/lib/python3.8/site-packages/nltk/data.py in find(resource_name, paths)
582 resource_not_found = f"\n{sep}\n{msg}\n{sep}\n"
--> 583 raise LookupError(resource_not_found)
584
LookupError:
**********************************************************************
Resource words not found.
Please use the NLTK Downloader to obtain the resource:
>>> import nltk
>>> nltk.download('words')
For more information see: https://www.nltk.org/data.html
Attempted to load corpora/words.zip/words/
Searched in:
- '/home/my_user_name/nltk_data'
- '/anaconda3/nltk_data'
- '/anaconda3/share/nltk_data'
- '/anaconda3/lib/nltk_data'
- '/usr/share/nltk_data'
- '/usr/local/share/nltk_data'
- '/usr/lib/nltk_data'
- '/usr/local/lib/nltk_data'
- '/data'
I used the manual installation part from here, https://www.nltk.org/data.html
But, instead of NLTK_DATA, I wanted to set the path from the notebook.
Any help? Thanks in advance.
This is completely frustrating that such a popular package nltk gives misleading messages.
The following message is just wrong!
Attempted to load corpora/words.zip/words/
It is not trying to load corpora from words.zip with folder words. It was attempting to load from nltk_data/corpora/words.
Attempted to load nltk_data/corpora/words/
so, solution is to add correct path manually as follows,
nltk.data.path.append("./data/nltk_data")
and then, put the unzipped file inside this, for example 'words' folder. And then access words as,
nltk.corpus.words.words()
I am facing the problem while making the build of the app. Some files are autogenerated and during that some of the import paths are written wrong:
In update_attendance.ast.gql.dart
// GENERATED CODE - DO NOT MODIFY BY HAND
import 'package:firm_mobile%5Csrc%5Cnetwork%5Cgraphql%5Coperations%5Cevents%5Cupdate_attendance%5C__generated__%5Cupdate_attendance.ast.gql.dart'
as _i2;
import 'package:gql/ast.dart' as _i1;
Error:
[SEVERE] ferry_generator:graphql_builder on lib/src/network/graphql/operations/events/update_attendance/update_attendance.graphql:
Could not format because the source could not be parsed:
line 1, column 213 of .: An escape sequence starting with '\u' must be followed by 4 hexadecimal digits.
╷
1 │ import 'package:firm_mobile\src\network\graphql\operations\events\update_attendance\__generated__\update_attendance.ast.gql.dart' as _i5;import 'package:firm_mobile\src\network\graphql\operations\events\update_attendance\__
generated__\update_attendance.data.gql.dart' as _i2;import 'package:firm_mobile\src\network\graphql\operations\events\update_attendance\__generated__\update_attendance.var.gql.dart' as _i3;import 'package:firm_mobile/src/networ
k/graphql/schema/__generated__/serializers.gql.dart' as _i6;import 'package:built_value/built_value.dart';import 'package:built_value/serializer.dart';import 'package:ferry_exec/ferry_exec.dart' as _i1;import 'package:gql_exec/gql_exec.d
art' as _i4;
│ ^^
╵
Where in the settings of Android Studio I can check or change how the / has to be interpreted (format settings)?
I am using Windows. On Mac this problem doesn't appear. But I need to solve it on Windows.
Apparently, it is the problem of the package ferry_generator on Windows' machines. It is still an open issue, but there are some possible solutions.
Check this discussion.
Downgrade was not an option for me, so i set in the pubspec.yaml the github link to the ferry_generator.
It is working by now, no one knows how it will be in near future. Hope, that the issue will be solved soon.
I am writing (hopefully) a simply AWS Lambda that will do an RDS Oracle SQL SELECT and email the results. So far I have been using the Lambda Management Console, but all the examples I've run across talk about making a Lambda Deployment Package. So my first question is can I do this from the Lambda Management Console?
Next question I have is what to import for the Oracle DB API? In all the examples I have seen, they download and build a package with pip, but that would then seem to imply using a Deployment Package (see above). Trying to import any of these modules listed in the examples simply give "No module named "...
After writing the above I dug into the boto3 API referrence and came up with:
import boto3
client = boto3.client('rds-data')
But it gives the error: Unknown service: 'rds-data'.
So I'm still lost.
As you can probably tell, I'm new to the Lambda environment. Any suggestions or examples would be greatly appreciated. Thanks.
This is an update of the solution using the 18c Oracle client libraries. If it wasn't for main solution it would have taken me a lot longer to get my code working. This will hopefully help anyone that follows.
(an aside - I tried getting it working with the instantclient_19_3 but went round in circles for a day, and then tried with instantclient_18_5 and it worked)
Files downloaded and used
instantclient-basic-linux.x64-18.5.0.0.0dbru.zip (all files)
cx_Oracle 7.2.2 (https://cx-oracle.readthedocs.io/en/latest/release_notes.html#releasenotes)
libaio.so.1.0.1 (as described in main answer, renamed to libaio.so.1)
This then gave these files in the zip (lambda_function.py is my python source code)
zip contents
Apparently, AWS Lambda is using an older version of boto3, which does not have rds-data yet.
So I'm afraid you will have to create a deployment package containing a more recent version of boto3.
One way to do this, would be to:
Create your lambda handler file (in this case named index.py).
def my_handler(event, context):
client = boto3.client('rds-data')
print(client)
# do stuff
return "hello world"
Add a requirements.txt file in the same folder, which will contain something like:
awscli >= 1.16.118
boto3 >= 1.9.108
Now run this (depending on the setup on your computer, you can use pip instead of pip3) in the directory/folder of your index and requirement file:
pip3 install -r requirements.txt -t .
zip -r somezipname .
Next, upload this zip and change your handler 'entry point' to index.my_handler. The code should now run without errors.
older version of boto3 does not support rds-data.
but you can deploy package with zip folder.
i recommend you to use import cx-oracle
for that install cx-oracle using pip
and upload zip packages. check this
[How can I access Oracle from Python?
After much groaning and gnashing of teeth I have come up with a successful solution.
rds_data (as confirmed by AWS Support) is only supporting Aurora Databases. Wish the AWS documents mentioned this. 8{(>
Thanks to the answers above as well as Jason Landrey for hints as to the solution.
In order to access RDS/Oracle, you need to use cx_Oracle. But wait, there's more.
cx_Oracle is not in the standard Lambda environment, so you need to bring your own. My development environment is on Windows, but the Lambda environment is Linux. So, you need to download and install in your packaging directory I got mine from https://pypi.org/project/cx-Oracle/#files. Install locally with:
pip install cx_Oracle-7.1.2-cp37-cp37m-manylinux1_x86_64.whl -t .
You will see several file appear in . Then you need to find a Linux system and download /lib64/libaio.so.1.0.1 and call it libaio.so.1 in your packaging directory.
And then you need to download both Oracle instant client basic and SDK packages from http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html.
Create a zip file with all these items (including your own Python source). In doing so, rename Oracle instant client files libclntsh.so.11.1 to libclntsh.so and libocci.so.11.1 to libocci.so.
Upload the zip to a S3 bucket as the direct deploy is limited to 66mb and this zip is a bit larger.
Create a Lambda with the appropriate IAM permissions and VPC access, install the package and it should be good to go.
I found that if you don't include all the instant client files you start getting Oracle errors about missing timezone and NLS information.
List of zip contents (for me, YMMV):
7996693 08/24/2013 12:30 libnnz11.so
0 03/11/2019 16:10 cx_Oracle-7.1.1.data/
0 03/11/2019 16:10 cx_Oracle-7.1.1.data/data/
0 03/11/2019 16:10 cx_Oracle-7.1.1.data/data/cx_Oracle-doc/
0 03/11/2019 16:10 cx_Oracle-7.1.1.dist-info/
1325 03/13/2019 12:35 Email.py
1805 02/19/2019 21:11 cx_Oracle-7.1.1.data/data/cx_Oracle-doc/LICENSE.txt
163 02/19/2019 21:11 cx_Oracle-7.1.1.data/data/cx_Oracle-doc/README.txt
851 02/19/2019 21:11 cx_Oracle-7.1.1.dist-info/METADATA
628 02/19/2019 21:12 cx_Oracle-7.1.1.dist-info/RECORD
109 02/19/2019 21:12 cx_Oracle-7.1.1.dist-info/WHEEL
10 02/19/2019 21:11 cx_Oracle-7.1.1.dist-info/top_level.txt
2270301 02/19/2019 21:11 cx_Oracle.cpython-37m-x86_64-linux-gnu.so
2140 03/13/2019 14:21 getSecrets.py
5560 03/12/2019 08:48 libaio.so.1
53865194 08/24/2013 12:30 libclntsh.so
118738042 08/24/2013 12:30 libociei.so
7633 03/13/2019 16:39 scheduleReports.py
I tried to install wand 0.4.4 on a windows 7 (64 bit).
I installed imagemagick binary (ImageMagick-6.9.3-1-Q16-x64-dll.exe).
Then set MAGICK_HOME environment variable to the path of ImageMagick.
Finally, I installed wand through pip in Anaconda (python 2.7.13).
When I run 'from wand.image import Image' I get the following error:
----> 2 from wand.image import Image
3 # from PIL import Image as PI
D:\Anaconda2\lib\site-packages\wand\image.py in <module>()
18
19 from . import compat
---> 20 from .api import MagickPixelPacket, libc, libmagick, library
21 from .color import Color
22 from .compat import (binary, binary_type, encode_filename, file_types,
D:\Anaconda2\lib\site-packages\wand\api.pyc in <module>()
178
179 try:
--> 180 libraries = load_library()
181 except (OSError, IOError):
182 msg = 'http://docs.wand-py.org/en/latest/guide/install.html'
D:\Anaconda2\lib\site-packages\wand\api.pyc in load_library()
124 try:
125 tried_paths.append(libwand_path)
--> 126 libwand = ctypes.CDLL(libwand_path)
127 if libwand_path == libmagick_path:
128 libmagick = libwand
D:\Anaconda2\lib\ctypes\__init__.pyc in __init__(self, name, mode, handle, use_errno, use_last_error)
360
361 if handle is None:
--> 362 self._handle = _dlopen(self._name, mode)
363 else:
364 self._handle = handle
TypeError: LoadLibrary() argument 1 must be string, not unicode
What's going wrong?
What's going wrong?
This has been reported here. It'll most likely be fixed in the near-future.
The fix is to update two lines in api.py.
Locate file wand/api.py file.
Search for methods ctypes.CDLL called under load_library function.
Cast unicode variables to strings.
Change ctypes.CDLL(libwand_path) to ctypes.CDLL(str(libwand_path))
Change ctypes.CDLL(libmagick_path) to ctypes.CDLL(str(libmagick_path))
This is a Python 2.7.13 issue that will be closed with 2.7.14 release, which should come out around mid-2017; before this date you can use the fix suggested by emcconville directly editing the loading of native libraries for each required package or downgrade to Python 2.7.12.
Issue details and settlement patch on:
https://hg.python.org/cpython/rev/4ce22d69e134
I'm working with the BigQuery API on Google Cloud Platform and I've completed the Golang client library installation.
When I try to compile, I see the following errors:
[root#server ~]$ go install github.com/user/program
# github.com/user/program/handler
go/src/github.com/user/program/handler/file1.go:228: undefined:
"cloud.google.com/go/bigquery".ValueList
go/src/github.com/user/program/handler/file1.go:259: undefined:
"cloud.google.com/go/bigquery".ValueList
The offending line for 228 is:
227 for {
228 var values bigquery.ValueList
229 err := it.Next(&values)
At the top of the file I import the package, as normally
import "cloud.google.com/go/bigquery"
and have taken care to install the client library for Golang
https://cloud.google.com/bigquery/docs/reference/libraries#client-libraries-install-go
I can see that the cloud.google.com package is contained within my GOPATH and I see the ValueList type decleration inside of a file in there. It is therefore puzzling that I'm getting this error.
What's more: I can compile this fine on my Windows machine with no errors. It's only when I try to do the same thing on my CentOS VM that I run into this. Both are running go version go1.6.3.
Thank you.
#Spikey,
Hi, please make sure you've installed correct client.
Here's why:
After installing go get -u cloud.google.com/go/bigquery I see that they do not have an exported ValueList type(!). Only valuelist, i.e. unexported. Check line 39 of ~go/src/google.golang.org/cloud/bigquery/value.go
However, they do mention ValueList as an exported type in their docs(!), for example:
line 52 of ~go/src/google.golang.org/cloud/bigquery/doc.go
https://godoc.org/cloud.google.com/go/bigquery
line 164 of ~/go/src/google.golang.org/cloud/README.md
Also, ValueList is an exported type if looking directly at: https://github.com/GoogleCloudPlatform/google-cloud-go/blob/master/bigquery/value.go
So there's a confusion about installing a correct Google client.
Hope this helps!