Skip to content

Commit ba99521

Browse files
vi3itorqstanczyk
andauthored
Update deprecated FindPythonLibs (#307)
* Update deprecated FindPythonLibs * Set Python version and directories manually on Windows * Change CMakeLists variables according to the convention * Revert include dirs name for OpenGL * Update documentation and README.md * Use deprecated FindPythonLib on legacy systems Co-authored-by: qstanczyk <stanczyk@google.com>
1 parent d0ca87f commit ba99521

3 files changed

Lines changed: 47 additions & 51 deletions

File tree

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ python -m pip install --upgrade pip setuptools psutil wheel
6060

6161

6262
#### 2. Install GFootball
63-
#### 2a. From PyPi package
63+
#### Option a. From PyPi package (recommended)
6464
```shell
6565
python3 -m pip install gfootball
6666
```
6767

68-
#### 2b. Installing from sources using GitHub repository
68+
#### Option b. Installing from sources using GitHub repository
69+
(On Windows you have to install additional tools and set environment variables, see
70+
[Compiling Engine](gfootball/doc/compile_engine.md#windows) for detailed instructions.)
6971

7072
```shell
7173
git clone https://github.com/google-research/football.git
@@ -85,9 +87,8 @@ Next, build the game engine and install dependencies:
8587
python3 -m pip install .
8688
```
8789
This command can run for a couple of minutes, as it compiles the C++ environment in the background.
90+
If you face any problems, first check [Compiling Engine](gfootball/doc/compile_engine.md) documentation and search GitHub issues.
8891

89-
To compile the engine on Windows you have to install additional tools and set environment variables. See
90-
[Compiling Engine](gfootball/doc/compile_engine.md#windows) for detailed instructions.
9192

9293
#### 3. Time to play!
9394
```shell

gfootball/doc/compile_engine.md

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@ Finally, install [vcpkg](https://github.com/microsoft/vcpkg) by following a
2525
cd C:\dev
2626
:: Clone vckpg
2727
git clone https://github.com/microsoft/vcpkg.git
28-
cd vckpg
2928
:: Run installation script
30-
.\bootstrap-vcpkg.bat
31-
:: Return to previous directory
32-
cd ..
29+
.\vcpkg\bootstrap-vcpkg.bat
3330
```
3431

3532
If you have `vcpkg` already installed, consider updating it to the latest commit and running `.\bootstrap-vcpkg.bat`.
@@ -59,7 +56,7 @@ python -m pip install .
5956
```
6057

6158

62-
## macOS
59+
## macOS (both Intel processors and Apple Silicon)
6360

6461
First, install [brew](https://brew.sh/). It should automatically download Command Line Tools.
6562
Next, install the required packages:
@@ -75,11 +72,9 @@ git clone https://github.com/google-research/football.git
7572
cd football
7673
```
7774

78-
### Intel processor
79-
#### Installation with brew version of Python
75+
### Installation with brew version of Python
8076
It is recommended to use Python shipped with `brew`, because `boost-python3` is compiled against the same version.
8177
To check which Python 3 is used by default on your setup, execute `which python3`.
82-
For Intel-based Macs it should be `/usr/local/bin/python3`.
8378
If you have a different path, and you don't want to change symlinks, create a virtual environment with
8479
`/usr/local/bin/python3 -m venv football-env` or `$(brew --prefix python3)/bin/python3.9 -m venv football-env`.
8580

@@ -96,10 +91,10 @@ python3 -m pip install psutil
9691
Finally, build the game environment:
9792

9893
```shell
99-
python3 -m pip install . --use-feature=in-tree-build
94+
python3 -m pip install .
10095
```
10196

102-
#### Installation with conda
97+
### Installation with conda
10398

10499
If you installed the engine using `conda`, you might encounter the following error:
105100
`TypeError: __init__() should return None, not 'NoneType'` when trying to run the game.
@@ -112,17 +107,9 @@ conda deactivate
112107
$(brew --prefix python3)/bin/python3.9 -m venv football-env
113108
source football-env/bin/activate
114109
python3 -m pip install --upgrade pip setuptools psutil wheel
115-
python3 -m pip install . --use-feature=in-tree-build
110+
python3 -m pip install .
116111
```
117112

118-
### Apple Silicon
119-
The environment can be compiled and run on Apple Silicon. Until some dependencies (`opencv-python`, `numpy`, etc.)
120-
fully support new architecture, the required components should be installed manually beforehand,
121-
and Google Research Football should be installed without dependencies (`--no-deps`).
122-
123-
#### Installation with conda
124-
Python dependencies can be installed via `conda's` fork [miniforge](https://github.com/conda-forge/miniforge).
125-
But you may encounter a `TypeError` when running the game if you use `boost-python3` from `brew`.
126113

127114
## Linux
128115
Install required packages:
@@ -148,7 +135,7 @@ python3 -m pip install psutil
148135
Finally, build the game environment:
149136

150137
```shell
151-
python3 -m pip install . --use-feature=in-tree-build
138+
python3 -m pip install .
152139
```
153140

154141
## Development mode
@@ -158,7 +145,7 @@ in the [development](https://packaging.python.org/guides/distributing-packages-u
158145
(aka editable) mode by running:
159146

160147
```shell
161-
python3 -m pip install -e . --use-feature=in-tree-build
148+
python3 -m pip install -e .
162149
```
163150

164151
In such case, Python source files in projects can be edited in-place without reinstallation,

third_party/gfootball_engine/CMakeLists.txt

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ if(WIN32)
1111
endif()
1212

1313
if(${CMAKE_GENERATOR_PLATFORM} STREQUAL Win32)
14-
set(VCPKG_TARGET_TRIPLET x86-windows)
14+
set(VCPKG_TARGET_TRIPLET "x86-windows")
1515
elseif(${CMAKE_GENERATOR_PLATFORM} STREQUAL x64)
16-
set(VCPKG_TARGET_TRIPLET x64-windows)
16+
set(VCPKG_TARGET_TRIPLET "x64-windows")
1717
else()
1818
message(FATAL_ERROR "Unsupported Generator Platform, only Win32 or x64 are supported")
1919
endif()
@@ -33,14 +33,15 @@ set (CMAKE_CXX_STANDARD 14)
3333
if(UNIX)
3434
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS} -fPIC -g -O3")
3535
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -O3 -g")
36+
set(OpenGL_GL_PREFERENCE GLVND)
3637
endif(UNIX)
3738

38-
# Find needed libraries
39+
# Find required libraries
3940
FIND_PACKAGE(OpenGL REQUIRED)
4041
include_directories(${OPENGL_INCLUDE_DIR})
4142

4243
FIND_PACKAGE(SDL2 REQUIRED)
43-
include_directories(${SDL2_INCLUDE_DIR})
44+
include_directories(${SDL2_INCLUDE_DIRS})
4445

4546
if(UNIX AND NOT APPLE)
4647
FIND_PACKAGE(EGL REQUIRED)
@@ -62,35 +63,44 @@ include_directories(${SDL2_TTF_DIRS})
6263
include_directories(${SDL2_GFX_DIRS})
6364

6465
if(UNIX)
65-
find_package(PythonLibs 3 REQUIRED)
66-
else()
67-
set(PYTHONLIBS_VERSION_STRING $ENV{PY_VERSION})
68-
endif()
69-
70-
message("Using Python: ${PYTHONLIBS_VERSION_STRING}")
71-
string(REPLACE "." ";" VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
72-
list(GET VERSION_LIST 0 PYTHON_MAJOR)
73-
list(GET VERSION_LIST 1 PYTHON_MINOR)
74-
75-
if(WIN32)
66+
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12")
67+
find_package(Python COMPONENTS Development REQUIRED)
68+
else()
69+
# Starting from CMake 3.12 FindPythonLibs was deprecated in favour of FindPython.
70+
# But Ubuntu 18.04 and other older distributions have CMake version less than 3.12,
71+
# so we have to support the old behaviour for some time.
72+
find_package(PythonLibs 3 REQUIRED)
73+
string(REPLACE "." ";" VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
74+
list(GET VERSION_LIST 0 Python_VERSION_MAJOR)
75+
list(GET VERSION_LIST 1 Python_VERSION_MINOR)
76+
set(Python_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS})
77+
set(Python_LIBRARIES ${PYTHON_LIBRARIES})
78+
endif()
79+
elseif(WIN32)
7680
# find_package (Python COMPONENTS Development)
7781
# FindPython package searches for system-wide python installations first.
7882
# It was improved only recently (Jan 2021), so we can't use it for earlier py versions:
7983
# (see https://github.com/microsoft/vcpkg/pull/15221 )
8084
# To avoid version mismatch we point to vcpkg's libs directly
81-
set(PYTHON_LIBRARIES "${CMAKE_BINARY_DIR}/vcpkg_installed/${VCPKG_TARGET_TRIPLET}/lib/python${PYTHON_MAJOR}${PYTHON_MINOR}.lib")
82-
set(PYTHON_INCLUDE_DIR "${CMAKE_BINARY_DIR}/vcpkg_installed/${VCPKG_TARGET_TRIPLET}/include/python${PYTHON_MAJOR}.${PYTHON_MINOR}")
85+
string(REPLACE "." ";" VERSION_LIST $ENV{PY_VERSION})
86+
list(GET VERSION_LIST 0 Python_VERSION_MAJOR)
87+
list(GET VERSION_LIST 1 Python_VERSION_MINOR)
88+
set(Python_INCLUDE_DIRS "${CMAKE_BINARY_DIR}/vcpkg_installed/${VCPKG_TARGET_TRIPLET}/include/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}")
89+
set(Python_LIBRARIES "${CMAKE_BINARY_DIR}/vcpkg_installed/${VCPKG_TARGET_TRIPLET}/lib/python${Python_VERSION_MAJOR}${Python_VERSION_MINOR}.lib")
8390
endif()
8491

92+
message("Using Python: ${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}")
93+
include_directories(${Python_INCLUDE_DIRS})
94+
8595
# Include Boost Python.
8696
if(WIN32 OR APPLE)
87-
set(BOOST_PYTHON_VERSION python${PYTHON_MAJOR}${PYTHON_MINOR})
97+
set(BOOST_PYTHON_VERSION python${Python_VERSION_MAJOR}${Python_VERSION_MINOR})
8898
else()
8999
# Unfortunately different linux distributions are using different naming for boost-python
90-
# list of prefixes: Ubuntu, Debian, Some other distributions
91-
set(BOOST_PYTHON_PREFIXES python3-py python-py python)
100+
# list of prefixes: newer Ubuntu and other distributions, older Ubuntu, Debian
101+
set(BOOST_PYTHON_PREFIXES python python3-py python-py)
92102
foreach(BP_PREFIX ${BOOST_PYTHON_PREFIXES})
93-
set(BOOST_PYTHON_NAME ${BP_PREFIX}${PYTHON_MAJOR}${PYTHON_MINOR})
103+
set(BOOST_PYTHON_NAME ${BP_PREFIX}${Python_VERSION_MAJOR}${Python_VERSION_MINOR})
94104
string(TOUPPER ${BOOST_PYTHON_NAME} BOOST_PYTHON_NAME_UPPER)
95105
FIND_PACKAGE(Boost COMPONENTS ${BOOST_PYTHON_NAME})
96106
if(Boost_${BOOST_PYTHON_NAME_UPPER}_FOUND)
@@ -103,12 +113,10 @@ else()
103113
message(FATAL_ERROR "Boost Python not found")
104114
endif()
105115
endif()
106-
message("Using python_boost: ${BOOST_PYTHON_VERSION}")
116+
message("Using Boost.Python: ${BOOST_PYTHON_VERSION}")
107117

108118
FIND_PACKAGE(Boost REQUIRED COMPONENTS thread system filesystem ${BOOST_PYTHON_VERSION})
109-
include_directories(${Boost_INCLUDE_DIR})
110-
111-
include_directories(${PYTHON_INCLUDE_DIR})
119+
include_directories(${Boost_INCLUDE_DIRS})
112120

113121
include_directories(${PROJECT_SOURCE_DIR}/src)
114122
include_directories(${PROJECT_SOURCE_DIR}/src/cmake)
@@ -151,7 +159,7 @@ endif()
151159

152160
set(LIBRARIES gamelib menulib datalib blunted2
153161
Boost::filesystem Boost::system Boost::thread Boost::${BOOST_PYTHON_VERSION}
154-
${PYTHON_LIBRARIES} ${SDL2_LIBS_ALL} ${EGL_LIBRARIES} ${OPENGL_LIBRARY})
162+
${Python_LIBRARIES} ${SDL2_LIBS_ALL} ${EGL_LIBRARIES} ${OPENGL_LIBRARIES})
155163

156164
if(UNIX)
157165
set(LIB_NAME game)

0 commit comments

Comments
 (0)