r/learnpython • u/[deleted] • Jan 05 '24
Why are interpreters required for programming ?
i'm trying to learn python ....i'm hearing a lot of stuff about interpreters....just wanna know what are they for..why are they required...can i learn python without interpreter...without vs code or py charm
Cuz i wrote some codes in python and it worked without connecting python to interpreter ....why is an interpreter necessary
Plz enlighten me
53
u/K900_ SRE person // please don't DM me your questions Jan 05 '24
VSCode and PyCharm are IDEs, not interpreters.
10
u/notacanuckskibum Jan 05 '24
VSCode and PyCharm are Integrated Development Environments (IDEs) and one of the things they integrate is an interpreter.
Computers can’t understand and run Python (or JavaScript, or C…) You need an interpreter or a compiler to convert the English like syntax into something the computer can understand.
1
u/1maru May 02 '24
VSCode does not integrate the Python interpreter in any way that's meaningful to OP's question; rather, this part might sounds confusing instead. When you run your code through VSCode, VSCode isn't really doing anything other than starting the Python binary program along with passing it the path to the file it thinks is the main entry point.
1
u/notacanuckskibum May 02 '24
Yes, that’s how they are integrated.
1
u/1maru May 02 '24
Yeah, it's just confusing the way you're putting it because VS Code itself has nothing to do with the question 'what is an interpreter and why do we need them'
-16
u/outofband Jan 05 '24
VSCode is not an ide
6
u/okabe_rintarou-42 Jan 05 '24
It is essentially
-8
u/Krudflinger Jan 05 '24
It’s essentially a text editor
9
u/usrlibshare Jan 05 '24
And an lsp client, lsp server runner, gitclient, project structure manager, with bindings to linters, ci/cd tooling, compilers, has a builtin terminal, integrates with project management software...
...pretty sure that's an IDE my friend.
-7
u/Krudflinger Jan 05 '24
That’s a patchwork of features that are a developer environment. that they aren’t integrated together as a cohesive product is why it isn’t an ide, my friend. see differences between visual studio and vs code
1
u/sexytokeburgerz Jan 05 '24
Many will argue that but the silent majority will just call it an IDE once it has extensions for every language imaginable
1
u/usrlibshare Jan 05 '24
Pray tell, what is it then, in your opinion?
3
u/SisyphusAndMyBoulder Jan 05 '24
Isn't it just a text editor?
Though with all the plugins available, I think it's a moot point - most people just consider it an IDE after they configure it up
1
u/repocin Jan 05 '24
Even out of the box with no plugins, it's for far more IDE-like features than typical text editors do. Personally, I think I'd put it somewhere inbetween the two.
2
1
u/Plank_With_A_Nail_In Jan 05 '24 edited Jan 05 '24
lol the default install is like 2 clicks away from being a very good Python IDE....but apparently those two clicks make all the difference to pedants like you. Life is already hard enough without people making up nonsense rules like these for themselves.
2
u/outofband Jan 06 '24
There is no need to get heated up. I’m just stating how things are. Beside VSCode itself does market it as an editor and not an IDE.
13
u/TehNolz Jan 05 '24
Computers don't actually understand any of the code the average programmer writes. They can only understand machine code, so you need something that turns the code written by humans into machine code that your computer can execute. In Python's case, that job falls to the interpreter. It's why you need to install Python before you can actually starting using it.
VSCode and PyCharm are IDEs. They're tools you use to write and debug code, but ultimately you still need to use the Python interpreter to actually run it. You don't have to use an IDE if you don't want to (even Notepad will work), but the experience will suck.
9
u/BokoMoko Jan 05 '24
if your Python code is running, there is a interpreter being used.
VScode and Pycharm are not Python interpreters. They're code editors with integrated features, among them the integration with an interpreter that actually runs the code.
Have in mind that Python is an interpreted language, like JavaScript, BASIC and others. Each of them need its own interpreter.
What is happening is that you are indeed using an interpreter, you just don't know how.
Give us more details on how/where you run your Python code and we can make a good guess on what you're using to interpret your code.
5
u/mapeck65 Jan 05 '24
When you installed Python, the Python interpreter was installed. It is what executes your code.
5
u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 Jan 05 '24
....i'm hearing a lot of stuff about interpreters....just wanna know what are they for..why are they required...
Taking your question at face value, in its simplest form an interpreter is a program that takes a program written in a programming language it understands, parses it, and executes the program. To put it another way, if the language lacks a compiler you need an interpreter to run programs written in that language.
can i learn python without interpreter...
Technically speaking, yes, but not having a way to actually run the code you write would make it an arduous journey, hardly worth the effort, and even if in theory you came to understand the language in full you'd still lack practical experience in using the language and would likely be stumped by errors related to the filesystem or third-party packages, for example.
without vs code or py charm
The others already touched on this, but those are integrated development environments, not interpreters. They'll give you access to an interpreter you've installed on your system, and you can develop programs without fancy editors if you really wanted to, but in the professional world the only metric that matters is getting work done. And both PyCharm and VS Code would absolutely help with that. There's a reason most people use them (or equivalents).
Cuz i wrote some codes in python and it worked without connecting python to interpreter ....why is an interpreter necessary
Again, it just sounds like you are confusing interpreters and code editors.
4
Jan 05 '24
There are two types of programming language: compiled and interpreted. A compiler takes your source code and converts it into machine code which you can then run without the compiler or the source code. An interpreted (or script) language is interpreted by an interpreter and so this and the source code are required at runtime. Compiled languages are faster and safer and are what most commercial software is written in. Interpreted languages are good for prototyping I.e. throwing things together quickly but you don’t normally distribute these because they’re inefficient, more likely to have runtime bugs, require a runtime and are easily copied / reversed / subverted. Python is usually an interpreted language but there are compilers available like cython. Hope that helps!
4
u/a1ic3_g1a55 Jan 05 '24
OP's gonna be so mad when he discovers compiling languages. "Just run my code, why do you need to compile?"
2
u/XxDonaldxX Jan 05 '24
An interpreter is a software that executes lines of code from (usually) a file.
When you download Python you are actually downloading Python's interpreter (and everything it needs to execute code).
When you execute a command like "python file.py" you are telling Python's interpreter to execute the lines of code inside file.py.
2
Jan 05 '24
Compiler takes source code and translates it into object file and with linker finally into the executable binary ready for executing on desired architecture only once. Interpreter takes source code and doesn't build exe file, but directly translates and executes every time you start it. Fun fact, every language can be either compiled or interpreted.
1
u/sausix Jan 06 '24
Interpreter C and C++? It breaks when macros and templates are involved.
Interpreting probably only works if code is executed top to bottom. Excluding those languages that allow late definitions.
2
u/Excellent-Practice Jan 05 '24
You can write Python in a text document, and it will work just as well as if you wrote it on paper. It might be properly formatted and valid code, but if you don't run it through an interpreter of some kind, it won't do anything. An interpreter is what takes your code and converts it into instructions that your computer can actually process so that it can return a result which can then be converted into a format that you can understand.
2
u/nekokattt Jan 05 '24
python IS the interpreter, AND the language.
When you run Python code, you are running it in a Python interpreter. You cannot run it without doing that (unless you are compiling it with a third party tool instead).
2
Jan 06 '24 edited Jan 06 '24
Python.exe is the interpreter.
If you compile your code into an app, you don't need an interpreter anymore.
I've never looked into this as I'm always tweaking my code, but I'm sure it's possible.
i use docker containers to 'install" my program into the cloud, but I'm still using python interpreter to run them.
2
u/Logicalist Jan 06 '24
"Interpreter" You keep saying that word. I do not think it means what you think it means.
1
Jan 05 '24
Open a terminal and enter python, that’s the interpreter, on you could call it CPython. It’s like a machine that could interpreter your lines of codes to byte code which will be executed by the python virtual machine lien by line.
1
Jan 05 '24
Of course not all implementations of python are based on C, but cpython is the most popular one and
1
Jan 05 '24
An interpreter interprets what the python code means so the computer can actually run it.
Without an interpreter the computer sees python code but doesn’t know what any of it means so it can’t run any of it
1
Jan 06 '24 edited Jan 06 '24
Well,
VS Code and Pycharm are just text editors, with tools that can help. Stuff like managing lots of files, checking your code, or things like that.
An interpreter is the "Python" program you installed, it takes in your code and does what the code says. At a somewhat simplistic level, you can think of everything in Python as a command to this interpreter, and the interpreter turns that command into an actual action on the computer.
You need an interpreter because otherwise, Python code would just be a text file. Computers can't do anything with that. They need it translated into actual instructions they can understand. That is what the interpreter does.
We don't (usually) write these instructions directly became that would be too painful. They are just numbers. A long list of numbers. Python simplifies that by creating a language we can write, and then the interpreter generates the instructions as it runs.
You do not strictly need a fancy text editor. You could use anything to write Python. But using something like VS Code or Pycharm will give you tools to make your life easier and can be helpful. Especially once your code gets bigger and more difficult to manage manually.
One of those nice functions they help with is running the Python interpreter for you so you don't need to deal with the command line.
1
Jan 06 '24
Python is an interpreted language which means you can type code into Python and it will interpret it -- parse and run it one line at a time. You can also save code in a .py file and have python interpret the file. Python modules are distributable files of python code that can be imported into other python files.
The advantages of an interpreted language is that you type in code and run it on the fly. You can run your code on any system that has an interpreter for the language, but you have to have the interpreter and any supporting modules running on the computer to run anything. You don't have to wait for compiling and linking every time you run the program, which speeds up debugging and testing.
C on the other hand is a compiled language, like most programming languages. You save C code in a file then you compile it using a C compiler which preprocesses, parses and complies your code into machine code. These days the compiler will automatically link it with compiled library code to produce a stand alone executable, though in the past this was a separate step. Now you have a single, compact, optimised executable file that can be run on the OS without the source code.
There are compilers for Python. Pypy is a just in time compiler that compiles and optimises code as it is run to speed it up. There are also compilers that compile python into java bytecode and C. Though usually python code was sped up by rewriting just the CPU intensive functions in compiled C.
These days on the internet complier and interpreter tend to be used interchangeably, as few people have done a proper CS degree and understand the nitty gritty bits of coding.
1
u/nog642 Jan 06 '24
The interpreter is what actually runs the code. If you ran your code, you used an interpreter.
VS Code and PyCharm are IDEs, not interpreters. You don't need an IDE, it's just useful.
1
u/razekery Jan 06 '24
Your console interprets python code because you installed python. When you execute python code in the console you call for its interpreter. That being said use an app that’s actually made for writing code, you will have a much easier time understanding and learning how to code and debug, plus they are free.
1
u/Maximus_Modulus Jan 06 '24
An IDE will effectively teach you how to program. I use IntelliJ for Java. Saves me having to Google and tells me when I do stuff wrong.
1
u/PhilipYip Jan 08 '24
You can use Python in the Terminal to run a script file created for example in notepad however this is generally used only for small script files and you will lack a lot of visual aids which help you write code and recognise mistakes... Your question is kind of similar to the concept of writing a word document in notepad versus using a word processor. The word processor essentially has a large number of grammar check tools which flag up whitespace issues, missing commas and bad spelling which can be easily missed when writing a document. In this case of a document bad grammar will only make the document look unprofessional. In the case of code bad grammar makes the code harder to understand and if the Python interpreter cannot understand the code it will not fail to run the Python script file. The Python interpreter essentially interprets your instructions and then instructs the Python program to execute them.
IDEs typically use the Python interpreter to apply syntax highlighting which will for example colour code a str differently from an instance name. (Reddit is essentially a text editor and applies no syntax highlighting in the example below).
greeting = 'Hello World!'
farewell = 'Bye!'Syntax highlight makes it easy to distinguish the two and reduces the changes of mixing the two up. Syntax highlighting will also show something is wrong for example if you forget to place a quote at the end of one of the str instances, the code will be unable to run. In an IDE the syntax highlight will show a problem in line 1 and also show an error beside the line number:
greeting = 'Hello World!
farewell = 'Bye!'IDEs typically also use the Python interpreter to look up identifiers in response to a prefix. For example if you input p, identifiers that begin with p display such as the print function:
greeting = 'Hello World!'The Python interpreter will also know that greeting is an instance of the str class and therefore when you input:
greeting.The str identifiers display.
IDEs also use the Python interpreter to look up the docstring, inputting print() will display the input arguments expected for the print function.
The ability to quickly look up the documentation as you type will prevent issues such as using the wrong name for an input argument in a function or failing to provide an input argument.
If you are having issues installing Python, creating a Python environment and then trying to install and configure an IDE, steps which often confuse beginners and likely the reason for the above question then I would recommend installation of the Anaconda Python Distribution and use of one of the preinstalled IDEs such as JupyterLab or Spyder to get started. Once familiar with these you can then look at configuring VSCode. VSCode is essentially a text editor like notepad but has a large number of extensions that give it the features of an IDE for code editing. If you need more details I put together a markdown tutorial here Anaconda and VSCode Installation which gives installation instructions and a good overview of the Python related programs in Anaconda.
0
Jan 05 '24
[deleted]
4
u/sausix Jan 06 '24
VS Code is not an IDE. It's a text editor. Or a code editor. It doesn't either call itself an IDE.
Plugins do push VS Code in the direction of being an IDE. But if plugins or external tools would count to change a text editor into an IDE, the same logic would apply to vim.
-70
Jan 05 '24
If ide's make it easier to write code than does it mean not using an ide would make me a better programmer than majority
76
u/Ok_Barracuda_1161 Jan 05 '24
If you can build the same projects at the same quality level in the same amount of time using a text editor, then sure you might have bragging rights but that's about it. For the most part people only care about what you output, not how you do it.
55
u/HunterIV4 Jan 05 '24
No. It would just make you a slower programmer than the majority.
I mean, if you want to be "better," write everything in assembly. Almost nobody will hire you, but you'll understand computer architecture better than most =).
34
u/Nomapos Jan 05 '24
In the same way that a carpenter who refuses to use hammers is a better carpenter than one who does.
0
Jan 05 '24
[deleted]
8
13
u/cyberjellyfish Jan 05 '24
No, just a slower developer that's more prone to write bugs and crap code.
5
u/r2k-in-the-vortex Jan 05 '24
You can hammer in a nail without a hammer, using, for example, a rock or maybe your forehead. Does it make you a better carpenter? Probably not.
4
u/POGtastic itertools evangelist Jan 05 '24
I'll go against the grain and say that a new programmer should introduce IDE features very slowly, to the point that starting with a blank text editor like Notepad++, GEdit, or Vim is a great idea. One reason for this is that you should know how your tools work, and dumping 5.8 metric shittons of VSCode extensions into your workflow is the exact opposite of that.
Once you're in industry, though, IDEs remove a ton of scutwork and let you focus on the important parts of your job.
3
u/rayofhope313 Jan 05 '24
You are mistaken in your understanding, if we say that not using ide makes you better programmer, then also not using Google to search for the issues you are facing makes you better programmer. Now we just told 99% (just to not say 100%) of programmer in the world they are not that good.
What makes you a better programmer is understanding how it works and why, how to write it more efficiently and with lower amount of bugs, how to test it, how to write clean code, to write comments for your code and so on. I know this might be discouraging, but you just started, use a good idea that helps you write cleaner code, recognise what are you writing, helps you run your projects and to finish your code faster. And just enjoy the journey. Don't try to rush it, especially at the beginning, understanding what is happening, why it is happening, and why it is written like that.
P.S: when you feel you are the worst programmer in the world and question your whole life keep going, we are go through that probably once a week then we feel like the smartest man alive. We all just cycle through these two feelings, especially at the beginning.
3
u/littledaimon Jan 05 '24
it will make you hate learning programming and learn slower. Because you will be staring at code for days not understanding why it does not execute without the ide being able to highlight all the syntax errors for you.
3
u/wezu123 Jan 05 '24
Your boss won't care about the way you write code. He will care about how much code you've written.
Your workmates using advanced IDE's, with autocompletion, hints, shortcuts, built-in documentation and copilot write 10k lines of code.
You write 5k lines of code using a notepad.
Guess who's getting fired.
3
u/vashekcz Jan 05 '24
I don't understand why this is downvoted so much, it's a fair question.
I do agree with the answers that say no. Although for a very long time I only used Notepad++ and took a sort of pride in it. Did that make me a "better" programmer? Probably not.
I would say, though, that if code is well readable and understandable without the use of an IDE, that's a sign of well written code.
1
u/carcigenicate Carcigenicate Jan 05 '24
In some ways, arguably, yes, but not in ways that really matter. If you're a programmer, your job is to complete work, and you should use tools that help you achieve that goal and keep you productive. Not relying on auto-completion and static analysis to catch errors may make you better at catching the issues yourself, but you're unlikely to be as accurate as the IDE, so at best, you're just hurting your productivity.
1
u/mandradon Jan 05 '24
You're going to hamstring yourself if you don't use an IDE or Text Editor that's geared toward coding.
The tools they offer are very useful and it doesn't make you a "better" programmer. Everyone makes mistakes, and the tools in the IDE/Text Editor are there to help you minimize them (for example, you forgot to close a brace or didn't put a closing quotation), as well as make your coding more efficient. Tab completion is very useful, syntax highlighting helps you read the code faster.
Black text on a white background with no error checking and no refactoring tools sounds slow.
1
u/IamImposter Jan 05 '24
Is the reasoning that you are doing it hard way so you become better?
Not at all.
The tools are there so that we can do our work faster and with ease. Like if I want to see the methods available for
Path, I can just doPath.and ide will show what are the methods available. I select the method and it will show me the parameters I need to pass. Otherwise I'll have to go back to documentation to get the same info.I can debug my code, put breakpoints, see value of variables and fix bugs with my code much faster. Otherwise I'll be cluttering my code with print statements just to see what's going on.
These tools are there to help us. Programmers before us faced these issues and came up with some solutions to make their as well as our lives easier. Let's use these tools and use the time we saved on our hobbies or family or whatever.
1
u/djshadesuk Jan 05 '24
If you went to a tyre/tire shop and a technician was removing wheel nuts/bolts with a spanner/wrench, instead of an air gun/wrench, would you think that person better than everyone else or doing exactly the same job just slower?
1
u/Aimee28011994 Jan 05 '24
a carpenter could swap his hammer out for a brick to hammer nails with.. it would technically work, but WHYY?
1
u/__versus Jan 05 '24
There is an argument that not using an ide will make you remember more but it will take you so much longer to get there that any benefit is wiped out with a huge margin.
1
u/Plank_With_A_Nail_In Jan 05 '24
You should always write your own code too never use libraries, need to read in a file then roll your own don't use stdio or whatever its called in your programming language.
1
u/nog642 Jan 06 '24
No. Anyone who can write code with an IDE can also write code without one, just slower.
1
u/seanys Jan 06 '24
Perhaps some advice from someone who might know a little better than you might be best right now. https://youtu.be/tzr7hRXcwkw
11
Jan 05 '24
[removed] — view removed comment
0
Jan 05 '24
Happy coding 🎉
Thanks... i wanna be great
1
u/Some_Guy_At_Work55 Jan 05 '24
I wish you the best of luck. I had an interesting journey, but if you're starting with Python I think you'll have a better time than me lol
-1
Jan 05 '24
if you're starting with Python I think you'll have a better time than me
Why though ?
4
u/Some_Guy_At_Work55 Jan 05 '24
My first language was Java and it was tougher to learn in my opinion.
30
u/JamzTyson Jan 05 '24
Greatly simplified:
Computers don't understand English. The Python interpreter converts Python code (which can be considered as "specially formatted English") into a simpler set of instructions called "Bytecode". These simplified instructions can then be run in a special piece of software called the Python virtual machine. The virtual machine converts the bytecode into low level binary instructions which are executed by the computer hardware.