简体   繁体   中英

Running Scons 2.2.0 on Windows 7 cmd

I installed SCons 2.2.0 in Python 2.7 on Windows 7. When a run "scons" from cmd i get the error message "scons is not recognized and an internal or external command" How can i solve this?


The problem is scons-2.2.0-setup.exe does not setup path in the system. The scons.bat and scons-2.2.0.bat are both found in "C:/Python27/Scripts" folder. Setting this to path does solve the problem. Now a new problem arises when trying a compile a simple C++ file with message "cl" is not recognized as internal or external command. (Windows 7 64 bit). Please any ideas may be helpful.

Did you install it using the SCons windows installer ? It should set everything up for you.

According to the SCons installation instructions , SCons should be installed here:

  • C:\\Python25\\Scripts
  • C:\\Python25\\scons

In your case, replace c:\\Python25 with the location of your pythong 2.7 installation.

Additionally, make sure the SCons python script is in your path. You may have to restart the cmd for the changes to path to take affect.

To use cl you need to use the Visual Studio command line and then run scons from there, its a .bat file and the scripts folder in your Python installation. Putting scripts in your path should resolve it as I recently did this myself.

I installed the 2 latest version (3.0.0 and 3.0.1).

Same problem, maybe because

  1. The Windows installer was looking for an installation of Python inside C:/Program Files... and it could only found Python 3.x (which is not compatible)

  2. setup.py has a small issue.

Anyway, I came with the following solution.

  1. Install with python setup.py install
  2. Go to your Python installation directory
  3. put either (or both) of the following files in subfolder Scripts :

    • scons.bat if you run scons from cmd
    • scons if you run scons from Msys or Cygwin

I have put below the code of these 2 scripts (the .bat was part of the source and the .sh has been inspired from it).

File <Python_dir>/Scripts/scons.bat

@REM Copyright (c) 2001 - 2017 The SCons Foundation
@REM src/script/scons.bat rel_3.0.0:4395:8972f6a2f699 2017/09/18 12:59:24 bdbaddog
@echo off
set SCONS_ERRORLEVEL=
if "%OS%" == "Windows_NT" goto WinNT

@REM for 9x/Me you better not have more than 9 args
python -c "from os.path import join; import sys; sys.path = [ join(sys.prefix, 'Lib', 'site-packages', 'scons-3.0.0'), join(sys.prefix, 'Lib', 'site-packages', 'scons'), join(sys.prefix, 'scons-3.0.0'), join(sys.prefix, 'scons')] + sys.path; import SCons.Script; SCons.Script.main()" %1 %2 %3 %4 %5 %6 %7 %8 %9
@REM no way to set exit status of this script for 9x/Me
goto endscons

@REM Credit where credit is due:  we return the exit code despite our
@REM use of setlocal+endlocal using a technique from Bear's Journal:
@REM http://code-bear.com/bearlog/2007/06/01/getting-the-exit-code-from-a-batch-file-that-is-run-from-a-python-program/

:WinNT
setlocal
@REM ensure the script will be executed with the Python it was installed for
set path=%~dp0;%~dp0..;%path%
@REM try the script named as the .bat file in current dir, then in Scripts subdir
set scriptname=%~dp0%~n0.py
if not exist "%scriptname%" set scriptname=%~dp0Scripts\%~n0.py
python "%scriptname%" %*
endlocal & set SCONS_ERRORLEVEL=%ERRORLEVEL%

if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto returncode
if errorlevel 9009 echo you do not have python in your PATH
goto endscons

:returncode
exit /B %SCONS_ERRORLEVEL%

:endscons
call :returncode %SCONS_ERRORLEVEL%

File <Python_dir>/Scripts/scons

#!/bin/bash

# Script to launch scons from MSys or Cygwin
# Inspired by scons.bat delivered with SCons

# Ensure the script will be executed with the Python it was installed for
BASEDIR=$(dirname "$0")
PATH="$BASEDIR:$BASEDIR/..:$PATH"

# Try the script named as the .bat file in current dir, then in Scripts subdir
BASENAME=$(basename "$0")
SCRIPT=${BASENAME%.*}
SCRIPTNAME="$BASEDIR/$SCRIPT.py"
if ! [ -f "$SCRIPTNAME" ]; then
    SCRIPTNAME="$BASEDIR/Scripts/$SCRIPT.py"
fi

# Run
python "$SCRIPTNAME" $@
SCONS_ERRORLEVEL=$?

# Check error code
if [ SCONS_ERRORLEVEL == 9009 ]; then
    echo "You do not have python in your PATH"
fi

# End
exit $SCONS_ERRORLEVEL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM