How to use Python3.2 with Dreampie? [UBUNTU] - python

I have a question.
I try to learn Python and of all programmer's tools I found Dreampie the most suitable. But, my dreampie always automatically sets Python 2.7. I found this topic and following the instructions, I changed both subp_main.py and subp_main.pyc (based on the first). Yet, it's still Python 2.7.
Telling truth, I suppose there should be some way to choose between the two versions, but I did not found anything in the Net or in program options. According to this topic writing "dreampie python3" inside the program should work, but dreampie inform me that the syntax is invalid (?).
[I quess the solution is very easy, but none of searchable things would help...]

You need to open a Terminal window (or Run dialog Alt+F2) and type in the command as follows and press Enter:
dreampie python3
It's not python syntax but shell syntax so you are running the dreampie application with python3 as argument.

Related

Open Python interactive session and editor

I am looking for some pieces of advices in order to accomplish a tiny task regarding Python. If someone would ask to provide a pic of a 'started interactive session of Python with your favorite editor with a Python script', what would you show to this person? Should it be a void script? How do you interpreter 'started interactive session'? How about your own favorite editor (I mean that you would suggest for Windows 10)?
Sorry for the triviality of my question,but I have just started with beginners' Python course
Just to make sure I am on the right way, if I have to submit to someone else a started interactive session and your favourite editor with a Python script, will be it sufficient to show the following windows as in the picture?
If you want to do interactive things, you probably just want to use jupyter notebook: https://jupyter.org/install#jupyter-notebook
You can always just type python at your terminal prompt if you have python installed, this will start an interactive session in your terminal, but jupyter is definitely easier to use once you get it set up.
Edit: regarding favourite editor, this is very much opinionated but I love sublime text. https://www.sublimetext.com/
Note that you probably would use one or the other: you would use a text editor to write scripts that could be run in a terminal, for example
# hello_world.py
print("Hello, world!")
then in your terminal
python hello_world.py
whilst you would use a jupyter notebook for example for quick experimentation or for demonstrating usage of your software to others.
In terms of interactivity, you should really check out Jupyter Notebooks. It's industry standard for a lot of tasks, widely used and with great performance and support. Also, Jupyter has an in-built code editor than can be run via localhost in your browser.
However, for a code editor, I will never stop recommending VSCode. Huge game changer, light-weighted and with support for pretty much any language. Jupyter notebooks can be run directly from VSCode, and the latest features that Microsoft introduced in this regard make using Jupyter inside VSCode really easy and intuitive. Also, extensions are a positive point as well.
If you're only planning on programming with Python, maybe checking out PyCharm is also a good idea, but I have working mainly in Python for the past 3 years and I have never missed anything on VSCode, even though I've tried PyCharm several times.
The simplest answer: go with the IDLE IDE, it comes bundled with Python by default. It starts with an interactive session, so you just type at the prompt (>>>):
print ("Hello, world!")
and your task is done, if it prints out your "Hello, world!" line.
In general, you start your python interactive session (python REPL, python terminal, python console, there are several terms for the same thing) and, since it's an interpreted language, everything you type in, Python will interpret and execute, if valid. Nevertheless, except for atomic examples, you'll want to use a code editor or IDE.
As a beginner, I'd avoid jupyter for the time being, it could get cumbersome. Stick with the default IDLE editor (you open a new file and type away) until you feel confident, then make the switch toward some editor or IDE that you fancy - Visual Studio Code is popular and has python debugger, vim is old as Bible, can run on a calculator, but it's a modal editor, best used with touch typing, Notepad++ is also good for coding...

How to colorise the Python repl

As we can see the difference between the images. In vim datatype and function are of different color. How can i bring color to my python repl.
I want to do it by myself. Please suggest me, how should I do this. Whether I should have to do something with stdout stream object or I have to change something in python interpreter and then build it from source (ohh I have to compile the python from source only to bring this change)
Sorry if there is some error in my question. Hopes you all will understand me.
You should probably have searched a little bit more first, because there are many answers here about this. Perhaps the best ones are:
bpython [NOT on Windows without hack.]
ipython
Change Python interactive prompt ">>>"
Some characters stick to my colorized prompt in Python cmd
Adding colors in python interpreter prompt, does not wrap properly
How to fix column calculation in Python readline if using color prompt

Python fails silently

I am trying to get started with Python, so I installed Python 3.8, from python.org (on Windows 10). I remembered to check the "Add to PATH" during the installation and I have confirmed that it has been added to path, as seen in the first image.
However, when I try to use any commands, whether it be python --version or python HelloWorld.py, nothing happens. I have tried both the traditional command line as well as Powershell. I have also tried replacing python with python3, the result is the same. As you can see in the second image, I get no errors, just a blank line. So it's not that it cannot find Python at all, it rather seems that something is wrong with the installation.
Have anyone else encountered this kind of behavior? I have tried re-installing Python as well as removing old installations.
Image 1: Python seems to be correctly added to PATH.
Image 2: Python fails to return any output. But also no error. Same thing happens with python HelloWorld.py.
Update 1 - Here is what I have tried so far:
Changing PATH to refer directly to exe file.
Using both Command Prompt and PowerShell.
Rebooting the PC.
Re-installing Python (including removing old versions).
Both the python and python3 command.
Update 2 - NameError: name 'python' is not defined
Update on the update: This was a wild goose chase. You are not supposed to be able to use that command in the interpreter, as described in this post.
So I tried to use the console from the python.exe file instead, and I got the following answer. However, from what I can find on it, it's normally a problem you encounter on elements of the code (like print()) and not on the python command...?
(image removed)
Update 3 - It works (kinda)
If I use the command py --version or py test.py it works. I have no clue why though...
After extensive research, I still cannot find an answer to my own question. But I have found a work around, which minimizes the consequences:
Instead of using python, simply use py.
This will invoke the Python launcher instead of Python itself (from what I've read). For most people this will be good enough, but it is not the same. So it might cause issues and version mismatch in certain scenarios.
Also, despite of this weird behavior, Python seems to run fine in Visual Studio Code, when using the "Run" button (or the py command in the terminal).

NameError: name 'ls' is not defined

I am running Windows 7 and just installed Python 2.7.4 and all I get are SyntaxError:'s. For example when I type:
>>>ls
I get
Traceback (most recent call last):
file "<stdin>", line 1, in <module>
NameError: name 'ls' is not defined.
I am new to Python and have no idea what the problem is.
Math calculations work as well as code seems to work. It's just commands like cd, ls, sudo apt-get update (and upgrade). Any guidance would be appreciated.
I think it's unfortunate that you're being downvoted so heavily here. If you're new to programming, this can be an honest mistake to make since a lot of tutorials assume that you're already familiar with the command line.
The main problem you have (as others have pointed out) is distinguishing between the operating system shell (which is also known as the console, terminal, command line, or command prompt) and the Python shell.
The operating system shell/command prompt is one of the fundamental ways you can interact with your computer. When you open the command prompt, you run arbitrary programs by typing in their name, run commands such as ls, sudo, cd, and apt-get.
If you type in python, for example, it'll cause the command prompt to start the Python shell. From there, you can run all of the Python commands, as usual. However, this is an entirely separate program with an entirely separate set of rules. The things you can do in the command prompt will not work in Python, and vice-versa.
Now, another point of confusion is distinguishing between the Windows command prompt and the Linux command prompt. You can install and run Python in both, but certain commands (in particular, sudo and apt-get) are available only on Linux operating systems. Unfortunately, the rules for using the Windows command prompt and the Linux command prompt differ somewhat, meaning that some instructions you find will be applicable only in one kind of operating system.
So no wonder you're confused! You're trying to learn about Python, but a good number of tutorials/articles will mention this second, entirely different system with hardly a word of introduction, and expect you to already know how to use it.
If you're curious about learning more about using the command line, here's a good crash course you can read. It'll teach you what you need to know for all 3 major operating systems (Windows, Linux, and Mac) and will hopefully make what you read online more clear.
I see from your profile you are learning about Raspberry Pi. A Raspberry Pi can use Debian (or Ubuntu, which is based on Debian) as the Linux distribution. The commands you are trying in Python are shell commands to run on that operating system.
Python is another command you can run on Raspberry Pi, but that doesn't mean that installing Python on Windows gives you those other commands on Windows too. You have two entirely different things confused here.
it's just commands like cd, ls, sudo apt-get update (and upgrade). Any
guidance would be appreciated
Python doesn't support those commands. Those are operating system level commands, not python level commands.
The Root of my problem was that I was not asking the right question. I was trying to run scripts in the interactive-mode and entering 'ls' and 'dir' to see where I was in the directory. With everyone's guidance I finally found the part in the Docs about Executable Python Scripts that said Windows automatically associates the 'py' extension with python.exe.
here. Then it all came together in my head. I had associated the 'py' extension with my editor instead of python and that I should have been at the Windows command prompt.
Thanks for everyone's help and quick responses.
The answers above are correct, but they don't help you with your issue!
One solution that will work in Python is:
%ls

Command Prompt Python

What is the benefit of running code through the command prompt/terminal vs an ide?
I've noticed recently when using the progressbar module of python that the progress text is updated on the same line in the command prompt window while the ide prints each text on the next line. Why are these different? Are they not running though the same interpreter?
The IDE adds an extra layer of software between the program and the python interpreter.
What you are seeing is probably that the IDE's output window is not a complete terminal emulator, and doesn't understand or ignores the commands that the progressbar module uses. to keep the output on the same line.
Have a look at ipython. It is a very nice environment for testing and running python code.
Each IDE is infact interacting via the command line and redirecting streams into it's implementation of showing those outputs, Each IDE has it's own way of doing this, command prompt is more powerful if you are expeirienced and easy to try one off scripts, try ipython which is great for beginners and learners alike for fast access to the programming environment and trying out module.

Categories