tl/dr python -m pip install -I --only-binary=":all:" --target lib networkx
, then add import sys; sys.path.append('path/to/lib')
to your script.
The problem is that in order for networkx to work, you'd need to include all of its dependencies and all of their dependencies in lib
. Unfortunately, running setup.py
won't do this for you, and not all of these dependencies will work on all platforms. For example, one of networkx's dependencies is numpy, which is implemented in C rather than python and has to be compiled separately for different target architectures.
All of this complexity illustrates why Python programs aren't usually distributed this way. If your program checker has access to the internet, the easiest solution would be to add a couple of lines to your program to install networkx via pip.
If you can't install packages over the internet, you can pre-build networkx and its dependencies in the lib
directory with the following command.
python -m pip install -I --only-binary=":all:" --target lib networkx
The -I
option is to ignore packages already installed on your machine. This should make sure all the necessary dependencies end up in lib
. You might need to use the --platform
and --python-version
flags to make sure you get the right versions of networkx and its dependencies for the online checker. If you don't know the platform or python version the online checker uses, add a couple of lines to your program to print the output of sys.platform
and sys.version
before you try to import networkx.
You'll also probably need to add lib
to the search path to make sure the python interpreter can find the modules you put in there. You can use sys.path.append('path/to/lib')
from the builtin sys
module for this.