I'm trying to use the cudamat library and I can't figure out how to use it from within Spyder. I have included the cudamat folder contents in my working directory, but when I try:
import cudamat as cm
I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "cudamat/__init__.py", line 1, in <module>
from cudamat import *
File "cudamat/cudamat.py", line 7, in <module>
_cudamat = ct.cdll.LoadLibrary('libcudamat.so')
File "/usr/lib/python2.7/ctypes/__init__.py", line 443, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python2.7/ctypes/__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libcudamat.so: cannot open shared object file: No such file or directory
When I run the my script using python from a console window, it works fine. To the best of my knowledge, I have set the working directory of Spyder to the correct location, which contains libcudamat.so.
Any ideas?
(Spyder dev here): You need to start Spyder from a console, so that it can grab its environment variables. I guess cudamat is not installed in a regular location and that's why Spyder can't find it by default.
Note: This is an Spyder limitation (i.e. not being able to read environment variables) that we plan to fix in the future.
Related
I'm using Visual studio and am trying to learn how to use scikit-learn/sklearn. I installed it and all the other packages using 'pip' without any problems.
I literally am only trying to import it. No other code yet.
Whenever I try to import it though, I get the following Error:
Traceback (most recent call last):
File "c:/Users/samir/Code/Machine Learning A-Z/Machine Learning A-Z (Codes and Datasets)/Part 1 - Data Preprocessing/Section 2 Part 1 - Data Preprocessing/Python/data_preprocessing_Samir.py", line 20, in <module>
import sklearn
File "C:\Users\samir\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\sklearn\__init__.py", line 82, in <module>
from .base import clone
File "C:\Users\samir\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\sklearn\base.py", line 17, in <module>
from .utils import _IS_32BIT
File "C:\Users\samir\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\sklearn\utils\__init__.py", line 20, in <module>
from scipy.sparse import issparse
File "C:\Users\samir\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\scipy\__init__.py", line 130, in <module>
from . import _distributor_init
File "C:\Users\samir\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\scipy\_distributor_init.py", line 61, in <module>
WinDLL(os.path.abspath(filename))
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\lib\ctypes\__init__.py", line 364, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
You need openslide windows libraries. Use either of the links below to obtain the binary.
32-bit: https://github.com/openslide/openslide-winbuild/releases/download/v20171122/openslide-win32-20171122.zip
64-bit: https://github.com/openslide/openslide-winbuild/releases/download/v20171122/openslide-win64-20171122.zip
After installation, open directory to which you installed to, and find the "bin" folder and add it to your windows path.
To add the path to "bin" folder to the Path variable, start the Run box and enter "sysdm.cpl"
This should open up the System Properties window. Go to the "Advanced" tab and click the "Environment Variables" button:
In the "System variable" window, find the "Path" variable and click Edit:
enter image description here
Position your cursor at the end of the Variable value line and add the path to the python.exe file, preceeded with the semicolon character (;). In our example, we have added the following value: ;C:\Python34. (But for you, add the openslide "bin" folder instead)
Close all windows. Now you can run sklearn.
my issue is that i've been trying to make an exe file with a .py that I created, but it doesn't work. I executed the converted .exe file from the console to see the log and I got this:
Traceback (most recent call last):
File "professors.py", line 10, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 531, in exec_module
File "docx2pdf\__init__.py", line 13, in <module>
File "importlib\metadata.py", line 551, in version
File "importlib\metadata.py", line 524, in distribution
File "importlib\metadata.py", line 187, in from_name
importlib.metadata.PackageNotFoundError: docx2pdf
[6940] Failed to execute script professors
I've been reading about the issue and it seems that pyinstaller doesn't recognize the docx2pdf import. I read in a website that I have to add it in a folder called site-packages, but it is supposed to have another folder inside called pyInstaller, which is not there. I also tried adding the folder manually but it still didn't work. I also tried with the --hidden-imports method but im not sure how to exactly use it.
I will have to apply this to other imports that I have also.
Any ideas? Thanks in advance!
I had a identical issue. I removed lines 7-13 from the docx2pdf module:
try:
# 3.8+
from importlib.metadata import version
except ImportError:
from importlib_metadata import version
__version__ = version(__package__)
and line 119...
print(__version__)
After that, it worked. Modifying the module probably isn't the best solution, and of course I'd recommend backing up the module before modifying it, but I hope it works for you too.
Currently, I am using Python 3.4 out of the Anaconda Suite. I have a file called "libPiCam.dll" within my working directory and I am trying to load it in this fashion:
from ctypes import cdll
def load(x):
"""Loads DLL library where argument is location of library"""
x = cdll.LoadLibrary(x)
return x
lib = load("PiCamLib")
But when doing that, I get this tracer back
Traceback (most recent call last):
File "<ipython-input-27-8d86fac88101>", line 1, in <module>
runfile('C:/Users/User/Documents/Python Scripts/PicamCode/PixisTest.py', wdir='C:/Users/User/Documents/Python Scripts/PicamCode')
File "C:\Users\User\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile
execfile(filename, namespace)
File "C:\Users\User\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 85, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)
File "C:/Users/User/Documents/Python Scripts/PicamCode/PixisTest.py", line 49, in <module>
piFunction = load(piFunctionLib)
File "C:/Users/User/Documents/Python Scripts/PicamCode/PixisTest.py", line 32, in load
x = cdll.LoadLibrary(x)
File "C:\Users\User\Anaconda3\lib\ctypes\__init__.py", line 429, in LoadLibrary
return self._dlltype(name)
File "C:\Users\User\Anaconda3\lib\ctypes\__init__.py", line 351, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application
What confuses me the most is that I have a file called "PiCam.dll" and load it in this fashion:
picamLibrary = 'picam'
picam = cdll.LoadLibrary(picamLibrary)
And loads using th eLoad method above. This works without error. I tried shaping my call to load libPiCam to be the same way, but I get the same error. As background, I created and compiled the "libPiCam.dll" file from a C++ file in order to wrap it, allowing me to call C++ functions from Python (I followed Calling C/C++ from python?).
So, what do I do?
I notice the naming isn't quite consistent: issue with libPiCam.dll vs "PiCamLib" doesn't work, while PiCam.dll vs "picam" does. Is it a an issue with case? Have you tried "libpicam"?
Otherwise, I wouldn't be surprised with it being an issue with the Anaconda distribution itself. I've had several issues that turned out to be bugs that occur when Anaconda interacts with windows. Ie. the c++ compiler not working properly, not being able to import pywin32 unless I run the .py script with IPython for some reason, etc.
On Windows 7 machine, Pycharm (community or professional) and Python 3.4 (tried Anaconda 3 as well) were installed newly. There were not problems running Python scripts interactively in main editor. However, when I tried to select View > Tool Windows > Python Console, it generates the following error messages and more. Basically, I couldn't bring up a console window in Pycharm.
C:\Users\user\Anaconda3\python.exe -u C:\Program Files (x86)\JetBrains\PyCharm 4.0.5\helpers\pydev\pydevconsole.py 56743 56744
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 4.0.5\helpers\pydev\pydev_imports.py", line 21, in <module>
from SimpleXMLRPCServer import SimpleXMLRPCServer
ImportError: No module named 'SimpleXMLRPCServer'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 4.0.5\helpers\pydev\pydevconsole.py", line 20, in <module>
import pydevd_vars
File "C:\Program Files (x86)\JetBrains\PyCharm 4.0.5\helpers\pydev\pydevd_vars.py", line 9, in <module>
from pydevd_xml import *
File "C:\Program Files (x86)\JetBrains\PyCharm 4.0.5\helpers\pydev\pydevd_xml.py", line 7, in <module>
from pydev_imports import quote
File "C:\Program Files (x86)\JetBrains\PyCharm 4.0.5\helpers\pydev\pydev_imports.py", line 23, in <module>
from xmlrpc.server import SimpleXMLRPCServer
File "C:\Users\user\Anaconda3\lib\xmlrpc\server.py", line 108, in <module>
from http.server import BaseHTTPRequestHandler
File "C:\Users\user\Anaconda3\lib\http\server.py", line 660, in <module>
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
File "C:\Users\user\Anaconda3\lib\http\server.py", line 851, in SimpleHTTPRequestHandler
mimetypes.init() # try to read system mime.types
File "C:\Users\user\Anaconda3\lib\mimetypes.py", line 348, in init
db.read_windows_registry()
File "C:\Users\user\Anaconda3\lib\mimetypes.py", line 255, in read_windows_registry
with _winreg.OpenKey(hkcr, subkeyname) as subkey:
TypeError: OpenKey() argument 2 must be str without null characters or None, not str
Process finished with exit code 1
Couldn't connect to console process.
-----------------these messages were showed up in "Python Console"-------------
You need to change your working directory. Go to File->Settings->Build, Execution, Deployment->Console->Python Console and then change or provide a directory where you have read and write access in the Working directory box.
The configuring of pycharm in the presence of various development configurations is a bit of a black art IMHO.
The most effective mechanism I've found for pinning this down is put random strings into the various settings dialogs, Interpreters, consoles, tests , servers and observe the command lines submitted to the interpreter VERY carefully.
Hardly a satisfactory approach but it will sort out what is going where and to a certain degree what effects what.
The other think that helps me are screenshots of the settings and testing dialogs of working installations.
Again, a bit rough and ready but it has got me up and running again after a long period of successful debugging followed by pycharm amnesia.
I had same problem. I reinstalled python and default directories have changed.
Then I just refreshed interpreter here File->Settings->Build, Execution, Deployment->Console->Python Console and here File->Settings->Project: <YOUR_PROJECT>->Project Interpreter.
If you will open new projects interpreter will need choose again (?)
I got it resolved by setting the interpreter in Preferences and project interpreter.
I'm using module transliterate.py from standard translit python libraries.
When I compile my GUI application, it raises the next error.
Traceback (most recent call last):
File "C:\Users\...\...\build\Rman\out00-PYZ.pyz\addobjectdialog", line 265, in OnTextName
File "C:\Users\...\...\build\Rman\out00-PYZ.pyz\core.utils", line 536, in translit
File "C:\Users\...\...\build\Rman\out00-PYZ.pyz\transliterate.utils", line 41, in translit
File "C:\Users\...\...\build\Rman\out00-PYZ.pyz\transliterate.utils", line 29, in ensure_autodiscover
File "C:\Users\...\...\build\Rman\out00-PYZ.pyz\transliterate.discover", line 27, in autodiscover
WindowsError: [Error 3] : 'C:\\...\\...\\AppData\\Local\\Temp\\_MEI11122\\transliterate\\contrib\\languages/*.*'
How I understand, I have to place
that lib somewhere within my application. But I just compile one .exe file, so wouldn't like to keep yet one file with my exe.
BTW, app is ran under Win 7 / 32bit.
Thanks.
That may be one of those libraries that you have to include explicitly. I know I had to do that from time to time with py2exe. See the following docs for more information:
http://pythonhosted.org/PyInstaller/#options-for-finding-imported-modules-and-libraries