ImportError: no module named 'SDCard' - micropython

I'm using Thonny version 3.3.13 on Windows 10 to program Raspberry Pi Pico.
The main program is main.py. I have no issues with it (examples are working), except any local imports.
I'm following this tutorial.
It is not duplicated, as I've searched and tested many version of import on StackOverflow and many other websites for hours.
My file structure:
sd_card_read
|-main.py
|-lib
|-__init__.py
|-SDCard.py
My main.py file:
import sys
print(sys.path)
import SDCard
#... the rest of the code
The error I'm getting is:
['', '.frozen', '/lib']
Traceback (most recent call last):
File "<stdin>", line 10, in <module>
ImportError: no module named 'SDCard'
How can I solve the import?
Notes:
I tried appending '.' and '/' to sys, it does not work. e.g sys.path.append('/')
I tried different versions of import, no luck. e.g from lib import SDCard

While Thonny allows you to run a file opened from your local computer, it ONLY allows importing modules from its own internal storage.
For me, this is confusing.
I ran "Save copy..." on all my module files, chose "Raspberry Pi Pico" and entered the filename manually.
Maybe there is another way of doing this in Thonny, as this is my first time using MicroPython on RPi Pico.

Try
from lib import SDCard
It works like that because lib is the package and not SDCard. SDCard is just a file in the package.

Related

How to import/compile uefi module using micropython?

Following the instructions on MicroPythonTestFramework/MicroPythonPkg, I can successfully run micropython.efi (using VS2015x86 instead of VS2017).
However importing the uefi module as given in the example on the above link fails:
FS0:\EFI\Python\> micropython.efi
MicroPython v1.9.4 on 2018-07-30; uefi version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import Lib.Uefi.uefi as uefi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: no module named 'Lib.Uefi'
MicroPythonDxe.efi is in the same folder as micropython.efi.
How do I do to compile the uefi module into MicroPythonDxe.efi?
In order to successfully import the Python UEFI module, you must have the UEFI Python library on your device and accessible.
The modules you are looking for are located in MicroPythonPkg/MicroPythonDxe/Lib/Uefi.
The device file system will end up looking something like below
FS0:\EFI\Python\Lib\Uefi\uefi.py
\features.py
\msr.py
\protocols.py
\register.py.... etc

Cannot import Tensorflow with Eclipse on Ubuntu16.04

The bug happens when I try to import Tensorflow on Eclipse. Tensorflow can
be imported when I directly run the python code without using IDEs (I test it and it works perfectly). I've also tested my codes on PyCharm, it's fine with Pycharm....
I've tested the LD_LIBRARY_PATH,PATH,CUDA_HOME variables with echo. I also tried to directly append the cuda libraries into the Ecplipse pydev interpreter setting. So it is really confusing me. I did face a similar question with another machine, but I solved it by modifying the ~/.bashrc file.
I'm using Ubuntu16.04, python2.7,eclipse Neon3, GTX1080ti.
Any ideas? Following is the bug information:
Traceback (most recent call last): File "/home/zernmern/workspace/test/p1/test.py", line 2, in <module>
import tensorflow as tf
File "/home/zernmern/.local/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/zernmern/.local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/home/zernmern/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/home/zernmern/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/zernmern/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/zernmern/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in
swig_import_helper_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
ImportError: libcusolver.so.8.0: cannot open shared object file: No such file or directory
Failed to load the native TensorFlow runtime.
Please let me know if more information is needed xD.
Ubuntu 16.04 uses Python 3.5 as the default system version of Python. You say that you are using Python 2.7. Did you install that yourself? It doesn't come with the OS. (And if you don't have a compelling reason to stay with Python 2.7, I would encourage you to switch to Py 3.x anyway, especially since you're working with a cutting-edge package like TensorFlow.)
Once you have two versions of Python on your system, it's easy to lose track of which packages you installed to which version of Python. I would check to see whether you happen to have installed TensorFlow, or parts of it, to the system Python 3.5 instead of your Python 2.7.
Finally, I find the solution from 'PyCharm cannot find library'
As the user 'Laizer' suggested:
The issue is that PyCharm(Here is Eclipse) was invoked from the desktop, and wasn't getting the right environment variables. Solution is to either:
invoke from the command line(i.e. Directly start eclipse by sh),
create a script to set environment and then invoke, and make a link to that script on the desktop,
or set environment variables on the desktop item

ModuleNotFoundError: Python 3.6 does not find modules while Python 3.5 does

I wanted to upgrade my python version from 3.5 to 3.6. Since I am using WinPython, I have downloaded and installed the recent version just as I did it before with version 3.5.
However, if I use version 3.6 I get a ModuleNotFoundError whenever I import a self-created module. A minimal example: I created a file t1.py that contains only a pass statement and a file t2.py containing the following code:
import t1
print("done")
Both files are in the same folder D:\MyProject\src. Now when I run the file with python 3.5, everything works fine:
'C:\Program Files\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\python.exe' D:\MyProject\src\t2.py
done
However, with python 3.6 I get
'C:\Program Files\WinPython-64bit-3.6.0.1Qt5\python-3.6.0.amd64\python.exe' D:\MyProject\src\t2.py
Traceback (most recent call last):
File "D:\MyProject\src\t2.py", line 6, in <module>
import t1
ModuleNotFoundError: No module named 't1'
I ran out of ideas what the issue could be and would appreciate new inspiration.
Would this work ? in t2.py
import os
__path__=[os.path.dirname(os.path.abspath(__file__))]
from . import t1
print("t2 done")
Python-3.6 changes its way of working, with the "python._pth" file next to python.exe (instead of "pyvenv.cfg" in previous versions)
If you don't want to modify your source, then you have to add "D:\MyProject\src" line in Python._pth file, or a relative path to it from python._pth location. in my example, it works with:
python36.zip
DLLs
Lib
.
..\test
import site
"http://bugs.python.org/issue29578?#ok_message=msg%20287921%20created%0Aissue%2029578%20message_count%2C%20messages%20edited%20ok&#template=item"
Other, simpler solution if you have no system-installed python: rename the "python._pth" file, next to "python.exe", as "pythonzz._pth"
The Python "Windows" maintainer just wrote that the simpler solution should be ok also with Python-3.6.0.

Tensorflow with Cuda, libcudart.so.7.5: cannot open shared object. eclipse (Liclipse)

When I import tensorflow in Liclipse I get the following error:
Traceback (most recent call last):
File "/home/user/Documents/workspace/project", line 13, in <module>
import tensorflow as tf
File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 23, in <module>
from tensorflow.python import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 45, in <module>
from tensorflow.python import pywrap_tensorflow
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
ImportError: libcudart.so.7.5: cannot open shared object file: No such file or directory
I have correctly installed tensorflow and cuda and both work fine from the terminal.
Tensorflow was installed via pip and I am using cuda 7.5 and cuDNN v4 and
I am using ubuntu 14.04.
The cuda samples compile and run perfectly as does tensorflow outside of Liclipse.
I have added cuda to both my path and LD_LIBRARY_PATH in .bashrc:
export PATH=/usr/local/cuda-7.5/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-7.5/lib64:LD_LIBRARY_PATH
I have the Liclipse python interpreter set up as:
/usr/bin/python-2.7
Any help would be much appreciated.
For the record, I had the same problem using Python 3 + PyDev + Eclipse (which I believe might be similar to Liclipse in this respect); what helped in my case was to add the cuda lib folder to my PYTHONPATH when running the IDE, e.g.,
PYTHONPATH=$PYTHONPATH:/usr/local/cuda/lib64 ./myEclipseFolder/eclipse
That made PyDev offer me the cuda lib folder for inclusion when setting up the Python interpreter, and then my tensorflow scripts worked.
Not a solution, but a work around. I'm simply running my scripts from the terminal. Its a pain for debugging but I am still unable to get TF to work with Liclipse.

Scipy and CX_freeze - Error importing scipy: you cannot import scipy while being in scipy source directory

I'm having trouble compiling an exe while using cx_freeze and scipy. In particular, my script uses
from scipy.interpolate import griddata
The build process seems to complete successfully, however when I try to run the compiled exe, I get the following message.
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
exec(code, m.__dict__)
File "gis_helper.py", line 13, in <module>
File "C:\Python27\lib\site-packages\scipy\__init__.py", line 103, in <module>
raise ImportError(msg)
ImportError: Error importing scipy: you cannot import scipy while
being in scipy source directory; please exit the scipy source
tree first, and relaunch your python intepreter.
After looking at scipy\ _init__.py file, there is the following:
if __SCIPY_SETUP__:
import sys as _sys
_sys.stderr.write('Running from scipy source directory.\n')
del _sys
else:
try:
from scipy.__config__ import show as show_config
except ImportError:
msg = """Error importing scipy: you cannot import scipy while
being in scipy source directory; please exit the scipy source
tree first, and relaunch your python intepreter."""
raise ImportError(msg)
I'm not entirely sure what is the problem here however although it seems that the erros is being thrown because there is a problem with the scipy config file. Possibly not being included in the build process. I'm quite a novice and hoping someone more experienced with generating build using cxfreeze can shed some light on this.
Incidentally, the scipy in use was installed from binaries here.
i have had the same issue. I added this code to the setup.py generated by cx_freeze:
import scipy
includefiles_list=[]
scipy_path = dirname(scipy.__file__)
includefiles_list.append(scipy_path)
Then, used includefiles_list as part of the build_exe parameter:
build_options = dict(packages=[], include_files=includefiles_list)
setup(name="foo", options=dict(build_exe=build_options))
I add the same problem and solved it using fepzzz method and including some missing packages:
additional_mods = ['numpy.matlib', 'multiprocessing.process']
includefiles = [(r'C:\Anaconda3\Lib\site-packages\scipy')]
setup(xxx, options={'build_exe': {'includes': additional_mods, 'include_files': includefiles}})
And using version 5.0.2 of cx-Freeze package, which solved an error when importing multiprocessing.process