Python Forum
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
clr issue
#1
hello all. I am new to python and was seeking some help.
trying to run the command
import clr
clr.AddReference("System.Data")
but when i write the second line i get AttributeError: module 'clr' has no attribute 'AddReference'.

Not sure what i am doing wrong. I just installed pytonnet.

Please help.

Thanks.
Reply
#2
Please provide your code and the full traceback it produce
Reply
#3
(Mar-23-2017, 12:16 PM)buran Wrote: Please provide your code and the full traceback it produce

.... and make sure your own source code file (or another file in the same directory) is not named "clr.py".
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#4
In an interactive session, import clr and then do dir(clr) so you can see what's there... since what you think is there obviously isn't.
Reply
#5
As far as I can see, clr does not have a method named AddReference
Reply
#6
According to the docs, http://pythonnet.sourceforge.net/readme.html#importing make sure your path to the assemblies are in the sys.path

Quote:Python for .NET uses the PYTHONPATH (sys.path) to look for assemblies to load, in addition to the usual application base and the GAC. To ensure that you can implicitly import an assembly, put the directory containing the assembly in sys.path.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#7
(Mar-23-2017, 11:15 PM)sparkz_alot Wrote: According to the docs, http://pythonnet.sourceforge.net/readme.html#importing make sure your path to the assemblies are in the sys.path

Quote:Python for .NET uses the PYTHONPATH (sys.path) to look for assemblies to load, in addition to the usual application base and the GAC. To ensure that you can implicitly import an assembly, put the directory containing the assembly in sys.path.

According to the OP the problem isn't in the import but when the code tries to use whatever was imported as clr.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020