Python Forum
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sudo apt Not Working
#1
Not sure this is the right place for this problem but it's where I thought was best. I'm relatively new to Python but did some programming in C+ many years ago.

Running Python 3.6.2 on Windows 10.

When I run "sudo apt-get upate" I get a syntax error.

Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> sudo apt-get update
  File "<stdin>", line 1
    sudo apt-get update
           ^
SyntaxError: invalid syntax
I don't have a problem running this on my PI.
Any idea what's going on? Think Thanks in advance.
Reply
#2
That is a Linux command.
On windows use:
python -m pip install -U pip
Reply
#3
sudo apt-get update is Linux command, not Python. You need to execute it in the shell/terminal. At the moment you try to execute it in the python interactive prompt.
Reply
#4
I get the same thing whether I try it in shell or terminal.
Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> python -m pip install -U pip
SyntaxError: invalid syntax
>>> sudo apt-get update
SyntaxError: invalid syntax
>>> 
This one is from the shell, first one from the terminal.
Reply
#5
You are trying to run from the python interpreter.
It is a command line command, so run from there.
Reply
#6
(Oct-04-2017, 11:59 PM)Dacdiver Wrote: Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)] on win32

This is a dead give away you are in the Python shell, as is the >>> prompt. To leave the shell, type exit() , this will return you to the command terminal.

As was pointed out thought, apt-get is a Linux command and will generate an error in Windows. 

What exactly are you trying to do?
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#7
Well, it seems that you don't know what is bash shell and Python interpreter. When you open a terminal you see '$' sign at the end of the prompt. This is the bash shell prompt. The Python interpreter prompt is '>>>'. So, in that interpreter you can run only python "commands". In the bash, the one with the '$', you can run linux shell commands and programs. apt-get is such a program so you run it when you see '$' sign at the end of the prompt.
At the end just open a terminal window and run 'sudo apt-get update'.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#8
(Oct-05-2017, 09:11 AM)wavic Wrote: When you open a terminal you see '$' sign at the end of the prompt. This is the bash shell prompt.

(The OP is using Windows 10 :-) ).
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#9
I always forget that there is something called Windows  Rolleyes
metulburr likes this post
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#10
I think you should use the Terminal of the Raspberry Pi. Inside it you can use the any sudo commands. Using the Python to use sudo commands is a bad idea.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  sudo RyAn 2 1,495 Nov-09-2021, 12:43 PM
Last Post: DeaD_EyE
  cant use ping, sudo or other commands in remote shell script. throwaway34 7 3,535 May-17-2021, 11:29 AM
Last Post: throwaway34
  Linux Script Sudo and "&" s3fac5 14 5,544 Aug-30-2019, 08:02 AM
Last Post: s3fac5
  do sudo su - user in python script aruntracer 2 15,085 Apr-02-2018, 12:45 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020