I am new to Python. I must precise that I don't clearly understand the relation between Cygwin and Python. I've seen tutorials of programmers launching a Python script in Cygwin with the following line:
python "file path"
I think that this line makes python build and run that script. My question is:
is it possible to directly write "print ("Hello World") " in Cygwin ?
By the way, are the three arrows (>>>) used to designate a Cygwin Shell input line?
Many thanks in advance!
Nicola
If you go to the Cygwin site, you can find the answers to all of your questions.
Cygwin provides a collection of tools that give functionality similar to a Linux distro on Windows. Cygwin also provides substantial POSIX API functionality. When programmers launch their python scripts using Cygwin, they are using the tools provided within the Cygwin library.
To avoid spoon-feeding while still answering your question, go into Cygwin and test it for yourself. What happens when you enter that command within Cygwin? Once you see the result, if you have any other questions, comment them on here.
Related
Edited to include a specific example
I am learning to use python and work in a windows 10 environment (although on 3 separate computers). I have gotten past the "add python to %PATH% issue" but continue to see odd outcomes when I call simple scripts from powershell compared to running them from the python terminal. For example, I often see that lines of code are duplicated, even simple print statements. A second repeating issue is that some (but not all) modules work fine in the python terminal but can't be found when running a script from powershell, despite using pip install within powershell to install it in the first place.
Rather then seeking help on a specific issue, I'm hoping for some guidance into how powershell and python interact that might help me understand or identify some commonalities in these issues I keep experiencing that are common from within powershell. If thats as simple as redirecting me towards another source even that'd be apprecaited. But my search results always turn up the common issue of powershell not knowing what python is, and needing to add python to the PATH. But as indicated, I have already gotten past this and can get %50 of my python to work from powershell. There must be something else perhaps obvious to others that I'm missing that can help me understand why some things aren't working while others are.
Thanks for taking the time to consider my problem and any advice is greatly apprecaited.
Here is an example from some code I am trying to get working, but in troubleshooting I have taken out a lot of code and am now only running what is shown that defines a dataframe and a print statement. Everything works line by line in python, but when I call the script from powershell, the print statement executes twice.
#!/usr/bin/python3
import pandas as pd
joedata = {'fpr': [0.2,0.4,0.8], 'tpr':[0.9,0.5,0.1]}
joeframe = pd.DataFrame(data=joedata)
print(joeframe)
Concerning modules, you probably have multiple versions of Python installed on your system. Calling pip in the Powershell doesn't mean that it will install for the Python installation which is called by default when you execute Python in the Powershell. So you should try to figure out on which version pip is installing packages and which version is actually used when executing a script.
EDIT: I tested the example that you gave in Powershell and I don't have the problem, it's working fine.
Moreover, for me, without doing any special configuration, in Powershell the commands pip and python refer to the same version of Python. If by default everything is ok, you should consider uninstalling Python and just running the installer again and let it manage the PATH, etc.
Good afternoon,
The Question
Is there a particular spot that the entries are stored, or is it just a local set of stored variables, for the windows version of Python?
The Context
I am curious about where Python.exe stores the entries typed out from the command line, not the Tkinter GUI. I'm particularly interested in this because I've noticed you can resort to previous entries if you are typing in raw_input(). There have been many discussions in regards to raw_input() and input() receiving some sort of default argument that is editable.
See. This link to a related SO question
Obviously this is very doable with Linux / GNU with modules that will allow you to take advantage of Bash's format. Windows users are unlucky in that regard.
Notes on these modules:
readline is GNU based and does not work properly in Windows.
pyreadline does not benefit the command line interpreter.
curses is GNU based and does not work at all in Windows.
A Follow up
The conclusion I'm arriving to is that if the user is given a pre-defined set of entries, you can limit what is entered into the command space.
P.S. - I understand it is much easier to just create a PySide, Tkinter or "other"-based GUIs to get around what I'm asking.
Sir James
On Windows 7, using the standard Python 3.7 command interpreter (not IPython or IDLE), the command history is stored in the file %USERPROFILE%\.python_history. This location is not used for Python 2.7.x, as the Python command history feature was introduced starting with Python 3.4.
I would really like to run my Win7 ipython interactively inside a proper terminal and shell provided by cygwin (mintty or rxvt would be great).
I have had some success with python, but IPython is not really cooperating. If we run this from rxvt bash prompt:
$ /cygdrive/c/pydir/python.exe -i
I end up with a fairly successful python interactive session. But vanilla python is just not as wonderful as IPython. So then I try this:
$ /cygdrive/c/pydir/ipython.exe
and the program just blocks the bash prompt, and seems to spawn an entirely separate process (which does not produce any windows, or show signs of stdin/stdout).
If instead I use this:
$ /cygdrive/c/pydir/python.exe -i /cygdrive/c/pydir/ipython-script.py
it is exciting at first, but you quickly realize that ipython is not properly engaging with the terminal. There is no readline support, poor cursor control, stdin seems to handle typical python, but there are no [out] prompts (although "prints" do spit out text), simple things like backspace/enter/tab seem completely broken (the cursor is very defiant), there is nothing like an ncurse buffer being maintained (you can just type over the ipy command prompts).
Once I have given up on the session, exiting becomes another problem. I can return to the bash prompt, but I have no standard input. It turns out that there is always a python.exe process hanging that must be killed from the Windows side (and it doesnt release stdin until it dies).
Is there a quick fix or alternate method to run Ipython in this manner? I can do most of my development using the cygwin binaries, but being able to run win32 binaries interactive would help tremendously when debugging/testing win32 specific python libraries.
P.S.:::: I really need tab-completion and clean output. I am trying to piece my way through a bunch of COM interfaces, and the only way I can get anywhere is with an interactive ipy session.
P.S.:::: I am using a 64-bit Cygwin and a 32-bit win32 python. Could this be simple mismatch?
Running win32 IPython.exe executables in cygwin is problematic at best. Best to run the cygwin Ipython version. Depending on the libraries you need, this can work just fine. But if you need to work with win32 compiled libraries, the cygwin Ipython will not work (as far as I know).
Overall, I still struggle for pleasant terminal experiences with ipython in Windows. There is no one solution that "just works". I have 3 different ways of interacting with IPython, depending on the job I need to get done.
Use cmd.exe (or Console.exe) and run the win32 ipython. This is the best way (in my opinion) for a vim+ipython workflow. This is very functional and fast. It will hurt your eyes a little, and still lacks a good "terminal" experience... but it will get the job done if you need to grind through some work. Extra Bonus: Seems like a few extra ipy %magics work better in this workflow.
Use cygwin and the ipython package that comes with cygwin. You lose "native" win32 support, but if you generally only need the standard library, this will look better and feel better (assuming you go all the way with CygwinX and run your favorite terminal).
Use win32 Ipython, and get QTConsole working. If your in Windows and you haven't already tried QTConsole, go get it right now and spend a little time setting it up. It can be extremely fast and pleasant (fonts that don't hurt my eyes!), and its loaded with features. Its biggest drawbacks: it doesn't handle some %magics well (like %edit, so I lose my vim+ipython workflow),it doesn't do system background processes well, and it won't always handle stdin/stdout like you would think. But, if you combine QTConsole with the cmd.exe ipython, and give it a little practice+patience, you can get a pretty decent "console" development workflow.
I have a program I've written in Python 2.7 on Windows, and I've been using py2exe with total success to make it into an exe (and associated files). However, a reasonable number of people who I want to use it are on Linux/OSX, and while some have been able to make the Windows version work with Wine, others have not been so successful. I've looked thoroughly into py2installer, py2app, freeze and others, but if I understand correctly (I am new to Python and very new to compiling) you need to run them on the system you want to compile them for, i.e. you can only compile for Linux on Linux and OSX on OSX. I don't want to distribute just the raw files because I want the source code to be obfuscated as it is inside a .exe, amd obviously not everyone has Python.
So, my question is: is there any way to compile for OSX or Linux, in Python, while on a Windows machine? And if not, what do you think the best alternative solution might be?
Code obfuscation is really not 'pythonic'. Even when packed into an .exe file, it's basically just the python interpreter and you source code (well, the .pyc files) zipped into one file. It is not as much as cross-compiling as it is about using a python package which does the thing you want (e.g, pack you code in a specific way) on linux.
Freeze will do this for you.
Most linux dists come with python built-in.
Get your linux box running! It's fun, useful, and you can always say 'On My Machine It Works!'. You can compile your code there / test your exe on Wine.
If for some reason you still can't get it to run, post a question!
Get Virtualbox, install Ubuntu in it, and build it "natively" in for Linux. These things work really well, and cross compilation is just asking for trouble. You're going to eventually need Linux to answer the support questions you'll get from these customers anyway! :(
I am trying to set up Python on Windows 7. I haven't used this language before so it seems strange to me.
I've downloaded lastest Python release 3.2.2 from official site and upadate path variable.
However I still can't even run simplest program ever like this :
print 'Hello, world!'
It says that there is a syntax error and the last character ' is highlighted with red.
I don't know if my path variable has been set properly. Here is where I installed Python :
C:\Software\Python32
So I added such a variable : var name = PYTHONPATH , var value = C:\Software\Python32\Lib
Is there something with auto-completion and with errors/warnings details ( which line, hint what can be wrong ), for example like Eclipse or NetBeans OR should I use this installed Python IDLE GUI for delevoping or stuff like NotePad++ ?
Actually what is this Python shell for ? - I know that I can type in some arithmetic operations here and I will get results, but is it used for something more advanced ? ( Is it used when I am writting something bigger ? )
Could someone describe simple way to write and execute a program ( or script I a total beginner so I don't really know what it is going on here ) ?
In Python 3.2 you have to use print in the below manner. The parentheses are mandatory. (print became a function in Python 3)
print('Hello World')
As Venk stated, the print statement in Python 2.x has been replaced with print() in 3.x, so your statement should read
print('Hello World')
Since you're new, here some things you should know about Python versions:
Python currently comes in two flavors: Python 2.x and Python 3.x.
Python 2.x has been in development since the late '90s, so most existing codebases, frameworks, and libraries are written in this flavor of Python. Each successive version is backwards compatible, so, for example, all code written in Python 2.4 can be run with Python 2.4+. Its current revision is 2.7.2, which was released last year.
Python 3.x is considered the "future" of Python, and purposefully breaks a lot of the conventions, such as the print statement, in favor of a clearer, more explicit language. Most libraries are working to port over to Python 3.x, but since there are extensive changes in the structure of the language, most library maintainers have not yet been able to release a Python 3.x compatible version with the full features of the Python 2.x version of the library.
If you're developing now, you should learn Python 2.x; otherwise, it's recommended you learn Python 3.x.
To answer your other questions:
Python's native IDLE is an excellent IDE, but if you're looking for something more advanced, you may want to try out Eclipse's PyDev extension or PyCharm. I personally prefer PyCharm, since it doesn't keep giving me errors when I'm importing/using nonstandard Python libraries/frameworks.
In addition, Python's shell is used to interpret Python scripts (in the background) and for interactive interpreting (i.e., quick and dirty testing), and can execute code you type into it. The latter, however, is not recommended, as a single syntax error in multiple lines of code can force you to retype all the lines to fix a single bug.
Furthermore, all Python scripts end in .py, so if you can see the file extensions, you can convert a text file into a Python script, and run from shell by typing python path/to/file.py. Note, however, that you still have to write a valid Python script, or it will not run.
I suggest A Byte of Python. It'll take you through install, REPL, syntax, and the std library.
The python shell is for entering code interactively.
Try the following: http://docs.python.org/tutorial/
I've been using Python on Windows 7 for 3 years now, and I strongly recommend Notepad++ as your editor/interpreter. It is ideal for people who want to play around with the language and are learning. Notepad++ can be customized for almost any language and is free for Windows. Follow this link
and take a look at how to conveniently use Notepad++ to execute Python scripts.