Module is not loaded, while running python script from terminal











up vote
0
down vote

favorite












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.










share|improve this question






















  • Do you maybe use different Python versions or installations?
    – user8408080
    Nov 22 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 at 15:14










  • What version of python are you using, and where is it located?
    – 2ps
    Nov 22 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 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 at 15:35















up vote
0
down vote

favorite












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.










share|improve this question






















  • Do you maybe use different Python versions or installations?
    – user8408080
    Nov 22 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 at 15:14










  • What version of python are you using, and where is it located?
    – 2ps
    Nov 22 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 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 at 15:35













up vote
0
down vote

favorite









up vote
0
down vote

favorite











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.










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 at 15:08









Sanjida lina

468




468












  • Do you maybe use different Python versions or installations?
    – user8408080
    Nov 22 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 at 15:14










  • What version of python are you using, and where is it located?
    – 2ps
    Nov 22 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 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 at 15:35


















  • Do you maybe use different Python versions or installations?
    – user8408080
    Nov 22 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 at 15:14










  • What version of python are you using, and where is it located?
    – 2ps
    Nov 22 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 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 at 15:35
















Do you maybe use different Python versions or installations?
– user8408080
Nov 22 at 15:13




Do you maybe use different Python versions or installations?
– user8408080
Nov 22 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 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 at 15:14












What version of python are you using, and where is it located?
– 2ps
Nov 22 at 15:24




What version of python are you using, and where is it located?
– 2ps
Nov 22 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 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 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 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 at 15:35












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Go to terminal type python3 if it shows python 3.7 then type python3 -m main.py or python3 main.py






share|improve this answer





















    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',
    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
    });


    }
    });














    draft saved

    draft discarded


















    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








    up vote
    1
    down vote



    accepted










    Go to terminal type python3 if it shows python 3.7 then type python3 -m main.py or python3 main.py






    share|improve this answer

























      up vote
      1
      down vote



      accepted










      Go to terminal type python3 if it shows python 3.7 then type python3 -m main.py or python3 main.py






      share|improve this answer























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        Go to terminal type python3 if it shows python 3.7 then type python3 -m main.py or python3 main.py






        share|improve this answer












        Go to terminal type python3 if it shows python 3.7 then type python3 -m main.py or python3 main.py







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 at 15:46









        Soleyman

        283




        283






























            draft saved

            draft discarded




















































            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            What visual should I use to simply compare current year value vs last year in Power BI desktop

            Alexandru Averescu

            Trompette piccolo