Module is not loaded, while running python script from terminal
I wrote a script which runs perfectly from Pycharm. But if i run this code from terminal it says no module is found.
Here is the code:
from rplidar import RPLidar, RPLidarException
lidar = RPLidar('/dev/ttyUSB0')
info = lidar.get_info()
print(info)
health = lidar.get_health()
print(health)
try:
for i, scan in enumerate(lidar.iter_scans()):
scan_data =
for d in scan: #d[0] : Quality of the measurement
'''if 0< d[1] <15: #d[1] : Angle of the measurement
print(d[2]/10) #d[2] : Distance of the measurement '''
if False:
lidar.stop()
lidar.stop_motor()
lidar.disconnect()
break
except KeyboardInterrupt as err:
print('key board interupt')
lidar.stop()
lidar.stop_motor()
lidar.disconnect()
except RPLidarException as err:
print(err)
lidar.stop()
lidar.stop_motor()
lidar.disconnect()
except AttributeError:
print('hi attribute error')
while i run this scipt as bellow:
python -m main.py
i got this error:
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/home/shahin/PycharmProjects/RpLidar/main.py", line 1, in <module>
from rplidar import RPLidar, RPLidarException
ImportError: No module named rplidar
shahin@shahin-UX360UAK:~/PycharmProjec
I will be so glad if you tell me how to overcome this problem.
And in the meantime, when i run this code in pycharm i want to catch KeyboardInterrupt from it. But its not working. Even i do Contro + c.
Can somebody tell me who to do KeyboardInterrupt in pycharm as well.
python
add a comment |
I wrote a script which runs perfectly from Pycharm. But if i run this code from terminal it says no module is found.
Here is the code:
from rplidar import RPLidar, RPLidarException
lidar = RPLidar('/dev/ttyUSB0')
info = lidar.get_info()
print(info)
health = lidar.get_health()
print(health)
try:
for i, scan in enumerate(lidar.iter_scans()):
scan_data =
for d in scan: #d[0] : Quality of the measurement
'''if 0< d[1] <15: #d[1] : Angle of the measurement
print(d[2]/10) #d[2] : Distance of the measurement '''
if False:
lidar.stop()
lidar.stop_motor()
lidar.disconnect()
break
except KeyboardInterrupt as err:
print('key board interupt')
lidar.stop()
lidar.stop_motor()
lidar.disconnect()
except RPLidarException as err:
print(err)
lidar.stop()
lidar.stop_motor()
lidar.disconnect()
except AttributeError:
print('hi attribute error')
while i run this scipt as bellow:
python -m main.py
i got this error:
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/home/shahin/PycharmProjects/RpLidar/main.py", line 1, in <module>
from rplidar import RPLidar, RPLidarException
ImportError: No module named rplidar
shahin@shahin-UX360UAK:~/PycharmProjec
I will be so glad if you tell me how to overcome this problem.
And in the meantime, when i run this code in pycharm i want to catch KeyboardInterrupt from it. But its not working. Even i do Contro + c.
Can somebody tell me who to do KeyboardInterrupt in pycharm as well.
python
Do you maybe use different Python versions or installations?
– user8408080
Nov 22 '18 at 15:13
Seems like some problem with python and module installation path. Check if you're using the right path to the module to work in terminal.
– Shiv_90
Nov 22 '18 at 15:14
What version of python are you using, and where is it located?
– 2ps
Nov 22 '18 at 15:24
Hi, even though i installed 3.7 but in my termial it shows Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34) @user8408080
– Sanjida lina
Nov 22 '18 at 15:34
But same code is working properly while i run it from pycharm should it also work properly while i run this from terminal? @Shiv_90
– Sanjida lina
Nov 22 '18 at 15:35
add a comment |
I wrote a script which runs perfectly from Pycharm. But if i run this code from terminal it says no module is found.
Here is the code:
from rplidar import RPLidar, RPLidarException
lidar = RPLidar('/dev/ttyUSB0')
info = lidar.get_info()
print(info)
health = lidar.get_health()
print(health)
try:
for i, scan in enumerate(lidar.iter_scans()):
scan_data =
for d in scan: #d[0] : Quality of the measurement
'''if 0< d[1] <15: #d[1] : Angle of the measurement
print(d[2]/10) #d[2] : Distance of the measurement '''
if False:
lidar.stop()
lidar.stop_motor()
lidar.disconnect()
break
except KeyboardInterrupt as err:
print('key board interupt')
lidar.stop()
lidar.stop_motor()
lidar.disconnect()
except RPLidarException as err:
print(err)
lidar.stop()
lidar.stop_motor()
lidar.disconnect()
except AttributeError:
print('hi attribute error')
while i run this scipt as bellow:
python -m main.py
i got this error:
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/home/shahin/PycharmProjects/RpLidar/main.py", line 1, in <module>
from rplidar import RPLidar, RPLidarException
ImportError: No module named rplidar
shahin@shahin-UX360UAK:~/PycharmProjec
I will be so glad if you tell me how to overcome this problem.
And in the meantime, when i run this code in pycharm i want to catch KeyboardInterrupt from it. But its not working. Even i do Contro + c.
Can somebody tell me who to do KeyboardInterrupt in pycharm as well.
python
I wrote a script which runs perfectly from Pycharm. But if i run this code from terminal it says no module is found.
Here is the code:
from rplidar import RPLidar, RPLidarException
lidar = RPLidar('/dev/ttyUSB0')
info = lidar.get_info()
print(info)
health = lidar.get_health()
print(health)
try:
for i, scan in enumerate(lidar.iter_scans()):
scan_data =
for d in scan: #d[0] : Quality of the measurement
'''if 0< d[1] <15: #d[1] : Angle of the measurement
print(d[2]/10) #d[2] : Distance of the measurement '''
if False:
lidar.stop()
lidar.stop_motor()
lidar.disconnect()
break
except KeyboardInterrupt as err:
print('key board interupt')
lidar.stop()
lidar.stop_motor()
lidar.disconnect()
except RPLidarException as err:
print(err)
lidar.stop()
lidar.stop_motor()
lidar.disconnect()
except AttributeError:
print('hi attribute error')
while i run this scipt as bellow:
python -m main.py
i got this error:
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/home/shahin/PycharmProjects/RpLidar/main.py", line 1, in <module>
from rplidar import RPLidar, RPLidarException
ImportError: No module named rplidar
shahin@shahin-UX360UAK:~/PycharmProjec
I will be so glad if you tell me how to overcome this problem.
And in the meantime, when i run this code in pycharm i want to catch KeyboardInterrupt from it. But its not working. Even i do Contro + c.
Can somebody tell me who to do KeyboardInterrupt in pycharm as well.
python
python
asked Nov 22 '18 at 15:08
Sanjida linaSanjida lina
488
488
Do you maybe use different Python versions or installations?
– user8408080
Nov 22 '18 at 15:13
Seems like some problem with python and module installation path. Check if you're using the right path to the module to work in terminal.
– Shiv_90
Nov 22 '18 at 15:14
What version of python are you using, and where is it located?
– 2ps
Nov 22 '18 at 15:24
Hi, even though i installed 3.7 but in my termial it shows Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34) @user8408080
– Sanjida lina
Nov 22 '18 at 15:34
But same code is working properly while i run it from pycharm should it also work properly while i run this from terminal? @Shiv_90
– Sanjida lina
Nov 22 '18 at 15:35
add a comment |
Do you maybe use different Python versions or installations?
– user8408080
Nov 22 '18 at 15:13
Seems like some problem with python and module installation path. Check if you're using the right path to the module to work in terminal.
– Shiv_90
Nov 22 '18 at 15:14
What version of python are you using, and where is it located?
– 2ps
Nov 22 '18 at 15:24
Hi, even though i installed 3.7 but in my termial it shows Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34) @user8408080
– Sanjida lina
Nov 22 '18 at 15:34
But same code is working properly while i run it from pycharm should it also work properly while i run this from terminal? @Shiv_90
– Sanjida lina
Nov 22 '18 at 15:35
Do you maybe use different Python versions or installations?
– user8408080
Nov 22 '18 at 15:13
Do you maybe use different Python versions or installations?
– user8408080
Nov 22 '18 at 15:13
Seems like some problem with python and module installation path. Check if you're using the right path to the module to work in terminal.
– Shiv_90
Nov 22 '18 at 15:14
Seems like some problem with python and module installation path. Check if you're using the right path to the module to work in terminal.
– Shiv_90
Nov 22 '18 at 15:14
What version of python are you using, and where is it located?
– 2ps
Nov 22 '18 at 15:24
What version of python are you using, and where is it located?
– 2ps
Nov 22 '18 at 15:24
Hi, even though i installed 3.7 but in my termial it shows Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34) @user8408080
– Sanjida lina
Nov 22 '18 at 15:34
Hi, even though i installed 3.7 but in my termial it shows Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34) @user8408080
– Sanjida lina
Nov 22 '18 at 15:34
But same code is working properly while i run it from pycharm should it also work properly while i run this from terminal? @Shiv_90
– Sanjida lina
Nov 22 '18 at 15:35
But same code is working properly while i run it from pycharm should it also work properly while i run this from terminal? @Shiv_90
– Sanjida lina
Nov 22 '18 at 15:35
add a comment |
1 Answer
1
active
oldest
votes
Go to terminal type python3 if it shows python 3.7 then type python3 -m main.py
or python3 main.py
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53433787%2fmodule-is-not-loaded-while-running-python-script-from-terminal%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Go to terminal type python3 if it shows python 3.7 then type python3 -m main.py
or python3 main.py
add a comment |
Go to terminal type python3 if it shows python 3.7 then type python3 -m main.py
or python3 main.py
add a comment |
Go to terminal type python3 if it shows python 3.7 then type python3 -m main.py
or python3 main.py
Go to terminal type python3 if it shows python 3.7 then type python3 -m main.py
or python3 main.py
answered Nov 22 '18 at 15:46
SoleymanSoleyman
433
433
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53433787%2fmodule-is-not-loaded-while-running-python-script-from-terminal%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Do you maybe use different Python versions or installations?
– user8408080
Nov 22 '18 at 15:13
Seems like some problem with python and module installation path. Check if you're using the right path to the module to work in terminal.
– Shiv_90
Nov 22 '18 at 15:14
What version of python are you using, and where is it located?
– 2ps
Nov 22 '18 at 15:24
Hi, even though i installed 3.7 but in my termial it shows Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34) @user8408080
– Sanjida lina
Nov 22 '18 at 15:34
But same code is working properly while i run it from pycharm should it also work properly while i run this from terminal? @Shiv_90
– Sanjida lina
Nov 22 '18 at 15:35