How can I fix the module import error when I run it on the command line after making SSH connection? - ssh

I am not working on lego mindstorm project using ev3-brick and successfully connected pc and ev3-brick using Pycharm and then transferred the code from my laptop to EV3-brick.
But whenever I try to implement the python file on SSH shell using terminal, the module import error occurs that no module named 'libs'. But since I transferred all the file and even set the path using export PYTHONPATH="${PYTHONPATH}:/home/robot/csse120/libs", it has to import all the modules. It seems that when I ran another file not using terminal, it correctly imports other modules or packages but whenever I run on the shell, it cannot find files on other packages.
I even tried inserting following code which is,
import os
os.environ['PATH'] += ':/home/robot/csse120/libs'
but it didn't work also in another file, it says it cannot import paho-mqtt thought it worked well when I didn't run it on the shell.
Can you help me solve this problem? I would appreciate your help.
enter image description here

Related

Running remote Pycharm interpreter with tensorflow and cuda (with module load)

I am using a remote computer in order to run my program on its GPU. My program contains some code with tensorflow functions, and for easier debugging with Pycharm I would like to connect via ssh with remote interpreter to the computer with the GPU. This part can be done easily since Pycharm has this option so I can connect there. However, tensorflow is not loaded automatically so I get import error.
Note that in our institution, we run module load cuda/10.0 and module load tensorflow/1.14.0 each time the computer is loaded. Now this part is the tricky one. Opening a remote terminal creates another session which is not related to the remote interpreter session so it's not affecting remote interpreter modules.
I know that module load in general configures env, however I am not sure how can I export the environment variables to Pycharm's environment variables that are configured before a run.
Any help would be appreciated. Thanks in advance.
The workaround after all was relatively simple: first, I have installed the EnvFile plugin, as it was explained here: https://stackoverflow.com/a/42708476/13236698
Them I created an .env file with a quick script on python, extracting all environment variables and their values from os.environ and wrote them to a file in the following format: <env_variable>=<variable_value>, and saved the file with .env extension. Then I loaded it to PyCharm, and voila - all tensorflow modules were loaded fine.

vscode, the interactive mode, I can open ipynb but cannot import the modules which I have installed

I have created a conda environment (say, called 'ds0') and installed some packages (e.g., python, pandas etc.). I then in vscode set the interpreter to be the one which I just created. I expect I could have my code working propery in the conda environment in vscode.
but then I have a problem, when I use the interactive mode in the ipynb file, I cannot import the packages,
e.g.,
import pandas as pd
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-11-f9ebee165770> in <module>
----> 1 import pandas as pd
ModuleNotFoundError: No module named 'pandas'
other code in the ipynb is running properly (e.g., to print a message etc.).
so it looks like vscode in the interactive mode is not using the right environment - but I did set the environment as 'ds0', and also if I save the ipynb file as a python script(e.g., as 'test1.py'), I can actually run it and vscode does recognize the pandas package.
so, how can I fix the issue so that I can run the code properly in the interacrive mode (e.g., in ipynb file).
** this is macbook m1 laptop, I just have the latest anaconda and vscode installed. I also tried to create additonal conda environments and the isse is the same. I am not sure if there is a problem with the ipykernel.
Thanks you!
I now have a solution to the problem - though I do not quite know if what I found was the culprit.
What I did and what did NOT solve the problem:
I installed ipython, ipykernel in the vscode terminal and the conda terminal (may be duplicated) manually - what happened was that, if I create a new ipynb file, I can select the both the interpreter and the kernel properly, and the code runs perfect - but if I open the previous ipynb file, I still have the problem - it looks like vscode is using different kernels for two different ipynb files
What I did: I reinstalled the Mac OS Big Sur (this may be unnecessary though) and I installed a clean miniconda and vscode - however this does not solve the problem. vscode still does not use the right kernel (but it looks like it uses the right interpreter/env which I created via conda). It looks like vscode is not using the right kernel (the icon in the upper right hand side suggests that the jupyter server local is 'disconnected'), also it puts a warning msg saying 'invalid version -final'
What I did and what DID solve the problem:
Then I deleted all the existing ipynb file and re- cloned from Github. this solves the problem - but I do not know why and how it solved the problem.
In the top right corner, you can see the name of the kernel used ("Python 3.8.1 64-bit: Idle", for example). Click on that, and select the kernel you want to use. That's how I fixed the problem. The Kernel is named within the ipynb file, and if there's a mismatch between that and your system, the notebook will not run.

after importing dill and dumping session , the notebook cannot be opened, the code cannot be retrieved

i worked on some experiment and wanted to find a way to save the lists of data i collected manually. i found dill and decided to use it .
installed via pip. typed in the following code:
import dill
dill.dump_session('notebook_env.db')
after that i closed the kernel and opened the notebook and to my shocking surprise got the following message:
Unreadable Notebook: /Users/nimrodros/Untitled.ipynb UnicodeDecodeError('utf-8', b'\x80\x03cdill._dill\n_import_module\nq\x00X\x08\x00\x00\x00__main__q\x01\x85q\x02Rq\x03}q\x04(X\x08\x00\x00\x00__name__q\x05h\x01X\x07\x00\x00\x00__doc__q\x06X#\x00\x00\x00Automatically created module for IPython interactive environmentq\x07X\x0b\x00\x00\x00__package__q\x08NX\x08\x00\x00\x00__spec__q\tNX\x0b\x00\x00\x00__builtin__q\nh\x00X\x08\x00\x00\x00builtinsq\x0b\x85q\x0cRq\rX\x03\x00\x00\x00_ihq\x0e]q\x0f(X\x00\x00\x00\x00q\x10X\x1a\x00\x00\x00eye_correction_middle_fallq\x11X\r\x00\x00\x00fuc=[1,2,3,4]q\x12X\x16\x00\x00\x00eye_correction_voltageq\x13X\r\x00\x00\x00fuc=[1,2,3,4]q\x14X/\x00\x00\x00import dill\ndill.dump_session(\'untitled.ipynb\')q\x15eX\x03\x00\x00\x00_ohq\x16}q\x17X\x03\x00\x00\x00_dhq\x18]q\x19X\x10\x00\x00\x00/Users/nimrodrosq\x1aaX\x02\x00\x00\x00Inq\x1bh\x0fX\x03\x00\x00\x00Outq\x1ch\x17X\x01\x00\x00\x00_q\x1dh\x10X\x02\x00\x00\x00__q\x1eh\x10X\x03\x00\x00\x00___q\x1fh\x10X\x02\x00\x00\x00_iq X\r\x00\x00\x00fuc=[1,2,3,4]q!X\x03\x00\x00\x00_iiq"X\x16\x00\x00\x00eye_correction_voltageq#X\x04\x00\x00\x00_iiiq$X\r\x00\x00\x00fuc=[1,2,3,4]q%%X\x03\x00\x00\x00_i1q&X\x1a\x00\x00\x00eye_correction_middle_fallq\'X\x03\x00\x00\x00_i2q(h%%X\x03\x00\x00\x00fucq)]q*(K\x01K\x02K\x03K\x04eX\x03\x00\x00\x00_i3q+h#X\x03\x00\x00\x00_i4q,h!X\x03\x00\x00\x00_i5q-X/\x00\x00\x00import dill\ndill.dump_session(\'untitled.ipynb\')q.X\x04\x00\x00\x00dillq/h\x00h/\x85q0Rq1ub.', 0, 1, 'invalid start byte')
why did this happen , and most importantly , how can i retrieve the code ? that data is already lost probably but i had valuable code there .
i believe if could open the file without running and just erase the line
import dill
dill.dump_session('notebook_env.db')
then i could again open the file without any problems . so maybe there's a way of doing that?
update
i tried to use
pip uninstall dill
hoped it would run the program again and stop when not recognizing dill , but it didn't go that way . still looking for a solution
update 2
tried to run the following on terminal :
iconv -f ISO-8859-1 -t UTF-8//TRANSLIT /Users/nimrodros/Untitled.ipynb -o /Users/nimrodros/New.ipynbh-MacBook-Pro-sl-nimrod:~ nimrodroTRANSLIT /Users/nimrodros/Untitled.ipynb -o /Users/nimrodros/New.ipynb
returned the following:
cdill._dill
_import_module
q__main__qqRq}q(__name__qhX__doc__qX#Automatically created module for IPython interactive environmentqX
__package__N__spec__q NX
__builtin__q
hbuiltinsq
q
fuc=[1,2,3,4]qX/import dillon_voltageqX
dill.dump_session('untitled.ipynb')qeX_ohq}qX_dhq]qX/Users/nimrodrofuc=[1,2,3,4]q%X_i1q&Xeye_correction_middle_fallq'X_i2q(h%Xfucq)]q*(KKKKeX_i3q+h#X_i4q,h!X_i5q-X/import dill
dill.dump_session('untitled.ipynb')q.Xdillq/hh/q0Rq1ub.iconv: -o: No such file or directory
iconv: /Users/nimrodros/New.ipynb: No such file or directory
h-MacBook-Pro-sl-nimrod:~ nimrodros$
the idea was to just convert it to a file that won't cause the notebook to crash so i could extract the valuable code. any ideas on how to continue?

Pycharm giving error on a script which is working from terminal (Module: Tensorflow)

I was working with the tensorflow(GPU version) module in Pycharm. If I run a script from terminal, it works as expected. However when I run the script from pycharm, it says:
ImportError: libcudart.so.7.5: cannot open shared object file: No
such file or directory
How do I resolve this?
Pycharm interpreter shows tensorflow as a package.
In the terminal, when I check for the version of tensorflow, it was the same as in pycharm (0.10.0rc0)
Looks like your CUDA_HOME or LD_LIBRARY_PATH configured correctly in the console, but not in PyCharm. You can check and compare their values, in console do
echo $CUDA_HOME
echo $LD_LIBRARY_PATH
In PyCharm (say, in your main script):
import os
print(os.environ.get('CUDA_HOME'))
print(os.environ.get('LD_LIBRARY_PATH'))
You can configure them for the given Run Configuration in Environment Variables section.
Better approach would be configuring those environment variables globally, so every process in the system would have an access to them. To do that you have to edit /etc/environment file and add original values, which you got from console.
Here are very similar problems: one, two, three.

Command line to run a program with both xlwt and abaqusConstants modules

Windows Machine, Python 2.4.
I have a program that imports both xlwt/xlrd and abaqusConstants module.
When I run my program with the command line: abaqus python abc.py, I get "ImportError: No module named xlwt/xlrd"
When I run my program with the command line: c:\python24\python.exe abc.py, I get "ImportError: No module named abaqusConstants".
The program ran perfectly when I ran it on my system where xlrd/xlwt was present in c:\python24\lib and Abaqus was installed in C-drive. When I tried to access xlrd/xlwt from my organisation's common share, the above problem appeared.
Is it because Abaqus is not present in the common share? How do I rectify this issue? Please tell me what command line to use.
the module abaqusConstants is only available in abaqus kernel executions of python so you need to be running it with abaqus python. Make sure that your PYTHONPATH variable is set properly to include the directory where xlwt/xlrd exists. see Using matplotlib (for python 2.6) with Abaqus 6.12 for a similar issue.