[SERVER-28879] MongoDB failed to build due to ImportError: No module named typing. Created: 20/Apr/17  Updated: 28/Jul/17  Resolved: 28/Jul/17

Status: Closed
Project: Core Server
Component/s: Build
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: KarenHuang [X] Assignee: Mark Benvenuto
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows Server 2012 R2 + VS2017 RTM + Python 2.7 + SCons 2.5.1


Issue Links:
Duplicate
is duplicated by SERVER-28881 MongoDB failed to build due to Import... Closed
Backwards Compatibility: Fully Compatible
Operating System: Windows
Participants:

 Description   

I tried to build MongoDB with master branch latest revision on Windows. It failed to build due to ImportError: No module named typing. This issue can be repro from revision c776e095 (https://github.com/mongodb/mongo/commit/c776e095ac25d0426624f4a84c03f0094c3c661f).

Python module typing is supported from python 3.5. But SCons does not run under Python version 3.5. Python 3 and above are not yet supported. Could you please take a look at this? Thanks!

You can repro this issue as the steps below:
1. git clone -c core.autocrlf=true https://github.com/mongodb/mongo D:\MongoDB\src
2. Open a VS 2015 x64 command prompt and browse to D:\MongoDB\src
3. scons all -j4

Error info:
C:\tools\Python2\python.exe buildscripts/idl/idlc.py --base_dir build/opt --header build\opt\mongo\idl\unittest_gen.h --output build\opt\mongo\idl\unittest_gen.cpp src\mongo\idl\unittest.idl
Traceback (most recent call last):
File "buildscripts/idl/idlc.py", line 23, in <module>
import idl.compiler
File "D:\MongoDB\src\buildscripts\idl\idl\compiler.py", line 26, in <module>
from typing import Any, List
ImportError: No module named typing
scons: *** [build\opt\mongo\idl\unittest_gen.cpp] Error 1



 Comments   
Comment by KarenHuang [X] [ 21/Apr/17 ]

Thanks for your quick response! Running command "pip.exe install -r buildscripts\requirements.txt" can install typing module. And this resolved my problem. Thank you again!

Comment by Mark Benvenuto [ 20/Apr/17 ]

Yes, I could just import typing and yaml. These are the only two strictly needed, and I do not believe these requirements are going to grow any time soon. This would work as long as scons and the idl compiler use the same version of python.

Comment by Bernie Hackett [ 20/Apr/17 ]

It looks like you could attempt to import all necessary modules in idl.py

Comment by Bernie Hackett [ 20/Apr/17 ]

Can you import packages during the build process? Most of those requirements aren't actually needed to build the server. You could just try to import typing and re-raise ImportError with a more helpful error message if it's not available.

Comment by Mark Benvenuto [ 20/Apr/17 ]

There are a few options:
You could use pkg_resources if the setuptools is installed. This is an optional site-package, and you would need to duplicate the contents of requirements.txt into python code.

You could runl pip check if pip is installed and the user has a recent version (> 8.0 I believe is the minimum, 1.x does not work). This is also optional site-package. You would then either try to search for the pip executable or try to load the pip program into the current python interpreter.

Comment by Andrew Morrow (Inactive) [ 20/Apr/17 ]

mark.benvenuto - Can we look into having SCons at startup probe the python environment for the requirements in the requirements.txt file and give a helpful error if they are not satisfied?

Comment by Mark Benvenuto [ 20/Apr/17 ]

We have a python requirements file here: https://github.com/mongodb/mongo/blob/master/buildscripts/requirements.txt

You can setup the necessary python modules for building by running:

pip.exe install -r buildscripts\requirements.txt

Also, please note that only VS 2015 is supported at this time. VS 2017 RTM is not supported by either SCons or the MongoDB source code.

Generated at Thu Feb 08 04:19:19 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.