3

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.

BunkerHer
  • 33
  • 1
  • 4
  • 1
    Is the python executable in a place listed in your `PATH` environment variable (try checking the output of `echo $PATH` in bash and `echo %PATH%` in Windows)? If not, add it and it should work. – hlt Jun 15 '14 at 17:05
  • If you are on Windows, then the executable is normally just `python`, not python3. – quamrana Jun 15 '14 at 17:06
  • @quamrana On cygwin, like on linux, python usually creates symlinks for either `python2` or `python3` when installed – hlt Jun 15 '14 at 17:08
  • @BunkerHer: Why have you opted to use cygwin to run python? – quamrana Jun 15 '14 at 17:09
  • @androyd I think that's probably it, Python isn't showing up under that command. and @ quamrana i'm just trying to get more comfortable with the bash commands. – BunkerHer Jun 15 '14 at 17:12
  • @BunkerHer Python itself does not need to be there, only the directory containing the `python3` symlink/file (usually `/usr/bin`), sorry if that was unclear... – hlt Jun 15 '14 at 17:14
  • @androyd cheers, got it to work now – BunkerHer Jun 15 '14 at 17:31
  • 3
    @BunkerHer Instead of editing your question with your answer, it is recommended that you post it as a seperate answer and accept it, so that others can clearly see it as a solution and also vote on it. – hlt Jun 15 '14 at 17:33
  • @androyd was wondering why i couldn't accept an answer haha - will need to wait 8 hours though to answer it myself – BunkerHer Jun 15 '14 at 17:34

2 Answers2

4

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.

me_and
  • 15,158
  • 7
  • 59
  • 96
0

(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

theRiley
  • 1,077
  • 13
  • 16