Python in Cygwin - python

I would like to know the difference in
installing Python, Paramiko packages in Cygwin and
Python is already installed in my Windows PC. I have installed Cygwin too (but without Python package) and in Cygwin terminal I do the following:
$echo "PATH=\$PATH:/cygdrive/c/Python27" >> .bash_profile
then,
source .bash_profile (after doing this I am able to run a Python script from cygwin terminal).
If the steps in point number 2 works good, then still do I need to install python packages from a Cygwin mirror site ? If I have not done it, then what I might miss while running Python through Cygwin ?
Thanks for your help.

No, you don't need to do so. In fact, CYGWIN will inherit the PC's PATH, plus with virtual PATH, you can input "echo $PATH" in CYGWIN and input "PATH" and the windows console, you could find that CYGWIN has more PATH setting than the windows. However, as you already overwrite the bash_profile, so it might not looks as what I said.
Besides, the most significant difference is that most of the CYGWIN executable files depends on CYGWIN.dll, while the typically windows files don't.

To use Python in Cygwin, you add this line to .bash_profile file.
export PATH=$PATH:/cygdrive/c/virtualenv/python2.7/Scripts
Hope for helps.

Related

Python shebang not working

Python is installed at:
C:/Python/Python35
At the top of my program I put:
#!/usr/bin/env python3
I opened windows command prompt and entered:
./words.py
The message I got was:
"." is not recognized
I was told this should work great on Windows so I'm confused?
./words.py will not work on the Windows command prompt, this way of executing scripts is meant for Linux/UNIX shells.
If you're using Python 3.3+:
The shebang lines will be obeyed by the Windows Python Launcher py if you have it installed (https://docs.python.org/3/using/windows.html#shebang-lines).
Make sure you have that installed and try launching using:
py words.py
There are multiple problems here.
Shebangs are a Unix thing. Windows does not recognize them at all. Instead, Windows uses file extensions.
There is no file named /usr/bin/env on Windows, so even if your shebang did work, it wouldn't do what you want.
The Python installer normally associates Python with .py files on installation. If it did not in your case (because you disabled the option?) you need to go fix that.
./something doesn't work on cmd.exe. It's .\something or just something.
Whoever told you, must have either misunderstood you or you misunderstood them.
Shebang lines have no effect with windows unless you're trying to use cygwin. The other reason you'll need them to ensure smooth transition between windows and linux if you're passing the code to someone who might be running on linux.
As far as the "." it is not used in windows. Its reason in linux OS is to inform the command that the script is in the current directory.
For windows all you'll need is: python words.py.
Your first problem is that Windows won't treat / as a path separator here. It has to be .\words.py or just words.py. That's why you get the error you see.
The next problem is that the shebang is not implemented by the windows command shell. It works on linux shells (and linux-like shells on Windows such as cygwin) because those shells read the front bit of executables to see how they should be executed. Windows does this by looking at the extension.

Python 3.4 command not found

I'm trying to do a doctest, I used the cd command in cygwin to navigate to where my .py file is located and then entered this command:
python3 -m doctest file.py
and I get this error in return:
-bash: python3: command not found'.
I'm on Windows 7. I've tried doing the doctest with the file in my Python 3.4 installation directory with no luck, either. I've also tried using the windows command prompt to the same effect. I feel like I'm missing something obvious but I'm not sure what.
EDIT: For future referance, I followed https://docs.python.org/3.3/using/windows.html#finding-the-python-executable and https://docs.python.org/3.3/using/windows.html#setting-envvars to get it to work.
It looks like you're using Cygwin, but haven't installed Cygwin's Python3. Having Windows Python installed isn't enough, and while there are ways of making Cygwin work with Windows Python, doing so has a lot of problems*.
To get Cygwin's Python3, run the Cygwin installer again (download it again if you need to), and select to install "python3" (it's under the "Python" category). Once the installation completes, you should find your command will work.
* Problems off the top of my head include different paths for installed modules, difficulties with line endings, different handling of terminals (i.e. MinTTY vs cmd), and different handling of file globs in the different shells.
(after installing the bare 'python3' package via the installer)
in my cygwin config, python is invoked by default as 'python3'
created an alias in .bashrc thusly :
alias python=python3
problem solved, python now points to the desired version

Python 3.2 doesn't work with python 2.7

I already have python 2.7 (installed using activepython). I'm trying to use python 3.2 just to learn more about it so i downloaded it from python.org
python 2.7 still works perfectly, but python 3.2 gives me this error when i try to open the ide.
and then I see the send error window, if i install python 3.2 using activepython i see the same error.
I'm using windows xp pro sp3 32 bit and i had the same error on sp2... How do I fix it?
EDIT #Zuljin
This is the first time that i use dependancy walker so could you give me a hand please
this is what i see
what does that mean? I already have these files...
I saw a lot of answers here. But, I think the file that you are trying to run is not correct
C:\Python32\Pythonw.exe
is not the one you use to open idle.
Open
C:\Python32\Lib\idlelib\idle.pyw
Python 2.x and 3.x can cohabitate perfectly in win xp and win 7, either 32 or 64 bits.
If you first installed the ActiveState Python distribution, be careful when installing python-3.2.2.msi.
When you arrive to the customize python 3.2.2 screen, (un)check 'register extensions' to make the feature unavailable (that is: do not register extensions).
I have installed this way both distributions in different computers without any problem so far.
Note: Check your environment variables. Only python 2.7 should be in the path (if you installed before the two distros you could have them both in the path. Remove python 3.2 path)
Edit:
From Ankit post I realized that in fact you were trying to open IDLE, maybe.
If you follow my installation instructions when you call idle.bat from the py3.2 idlelib folder you actually get idle for python 2.7 as this is what the call find in the windows path. To be able to open idle for py3.2 in the presence of python 2.7 as the registered python, I use a .bat file modified from that in the distribution:
idle_stay.bat
#echo off
rem Working IDLE bat for Windows - Custom bat for py3k as secundary python
C:\Python32\pythonw C:\Python32\Lib\idlelib\idle.pyw %1 %2 %3 %4 %5 %6 %7 %8 %9
The name idle_stay.bat is because I put this file in the folder where the official idle.bat is (C:\Python32\Lib\idlelib\idle_stay.bat). In this way it does not get overwritten each time I unisntall and reinstall a new version of python 3
It seems to me you have associated a *.py or *.pyw file extension type to some version of python.exe and/or pythonw.exe you aren't clear about. This is often, but not exclusively done from within Microsoft's "explore.exe" File Manager (I believe in Options).
I disagree that this is a reliable method:
C:\Python32\Lib\idlelib\idle.pyw
as this method will run whichever program is assigned to the "pyw" extension. That could be:
C:\Python32\pythonw.exe
or
C:\Python26\python.exe
or whatever might have happened to your file extension association as per OS or bad PATH environment variable setting. It is better to do something like this:
C:\Python32\pythonw.exe C:\Python32\Lib\idlelib\idle.pyw
where you are explicidly telling the OS to run the python executable from a specific path and selecting a specific python script in the file/folder hiearchy.
Another thing you can try to gather info is just:
python.exe -V
which will tell you the version number.
Another thing you can do:
Open a DOS command prompt and type:
set PATH=C:\Windows;C:\Windows\system32;C:\Python32
python.exe and note the version and whether is runs.
exit()
exit
Once working debug your PATH. You can use this Python script to gather intel.
If you turned off your WinXP findfile stuff (like I have) you can use this script:
inpath.py can help shed some light.
Run this python script like this:
Drop to a DOS prompt
cd to your folder with a working python.exe version.
and type python.exe inpath.py python*
where inpath is in that same folder for this test/debug.
inpath.py will search your path for all files associated as "runable" in your OS and that is in your "PATH" with the python*.* pattern.

Running a python script from the command line in Windows

I'm trying to run SnakeFood, to analyze a python project. I'm on a Windows machine and so far I've been able to figure out how to:
install Tortoise for Mercurial to download the SnakeFood code from the site
set the windows Path to accept python from the command prompt so I could do python setup.py install and got snakefood to go into my "site-packages" folder
Now, the documentation doesn't say anything else rather than:
sfood /path/to/my/project
I can't get this command to work. What am I missing?
Would this work?
python "DriveLetter:\path\to\sfood.py" "DriveLetter:\path\to\your\project"
Considering the documentation says "sfood /path/to/my/project" it most likely assumes a *nix environment. That leads me to the assumption that sfood probably has a shebang line.
On Windows you probably need to use "python sfood ". If "sfood" isn't in your PATH, you'll need to write the full path rather than just "sfood".
I was able to resolve this issue, on my Windows 7 machine with Python 2.7.3 installed, like so:
C:\> cd \path\to\snakefood\installation\folder
C:\path\to\snakefood\installation\folder> python setup.py install
...
C:\path\to\snakefood\installation\folder> cd C:\Python27\Scripts
C:\Python27\Scripts> python sfood \path\to\my\project
...

How to integrate Django and Cygwin?

I have a Windows box with cygwin, python and django installed.
Now I want to run django-admin, but when I do I get the error:
$ django-admin.py
c:\Python26\python.exe: can't open file '/usr/bin/django-admin.py': [Errno 2] No such file or directory
From here
For Windows users, who do not have symlinking functionality available, you can copy django-admin.py to a location on your existing path or edit the PATH settings (under Settings - Control Panel - System - Advanced - Environment...) to point to its installed location.
hope this helps
I just ran into the exact same problem. I've found that if you already have the windows version of python installed, it seems to get priority over the cygwin version. I solved the problem by editing /etc/profile and changed:
PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:$PATH
...to:
PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:
...which I think stops cygwin from adding the normal windows path. Once you've got that working, download django into some directory, move into that directory and type:
python setup.py install
I was having problems to begin with because I had omitted the 'python' bit at the start
As for the step on how to start your django in cygwin
first open your windows command prompt
then register the python environment by doing this:
Path %path%;C:\Python27;C:\Python27\Scripts
then now go to the installation folder of your cygwin
cd C:\cygwin
then run the cygwin.bat like this:
C:\cygwin>cygwin.bat <enter>
then cygwin will open, and type python to see if it now working
$ python
Voila we are done!
Sort of sounds like the windows version of Python is trying to run instead of the cygwin one. What happens if you type this:
$ python django-admin.py
Here I'm assuming
$ which python
Finds the cygwin version of python (which will be something like /usr/bin/python).
You may also try (temporarily) uninstalling the windows version of python and use only cygwin.
Help us help you. Is there a reason why you are running the windows python interpreter (c:\Python26\python.exe) as oppose to the cygwin python interpreter (/usr/bin/python.exe)? That could be your problem. So to troubleshoot that, you might consider removing the windows native interpreter or simply making sure the cygwin path is listed before the c:\Python26 path in the windows global PATH variable.
Add the location of your django/bin folder (or wherever else you keep django-admin.py) to your PYTHONPATH environment variable.
Like Brian mentioned you are running the Windows version of Python which won't work with the Cygwin installation.
A word of warning. When I first started using Django, I tried installing it in Cygwin and had a variety of problems and ended up switching to the regular Windows version of Python. Unfortunately, I didn't document all my issues, but I remember some of them had to do with the database libraries. Anyway, that was a few months ago when I knew less about Django than I do now. Maybe the problems I ran into have been solved and perhaps now that I know more I could get it to work, but running Django on Cygwin does seem to be the road less traveled. Good luck. :)
Just copy the django-admin.py to the current location you are working on for e.g
on Cygwin:
<root>/projects/
on your windows directory it will look like this:
C:\cygwin\home\<your computer name>\projects\
once you copy the file, you can create your project by typing this command:
$ python django-admin.py startproject mysite
and that's all - you have completed your first project using the Cygwin linux-like environment.
Add two lines to .bash_profile and .bashrc files (view their difference here). You can find them in C:\cygwin\home\[username]:
export PATH=$PATH:/cygdrive/c/python2.7
export PYTHONPATH=$PYTHONPATH:/cygdrive/c/python2.7/Lib/site-packages
Hope this helps

Categories

Resources