Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
pyOptSparse SNOPT precompiled library setup
#!/usr/bin/env python
# This is a modified version of pyoptsparse/pyoptsparse/pySNOPT/
# The modifications allow the user to use pyOpt with SNOPT precompiled libraries.
# Instructions:
# 1. Replace pyoptsparse/pyoptsparse/pySNOPT/ with this file.
# 2. Modify line 39 so that snopt7_path is the actual path to the location of the
# precompiled SNOPT library (libsnopt7.*).
# 3. Make sure to add the location of the library to DYLD_LIBRARY_PATH (for macOS)
# or LD_LIBRARY_PATH (for Linux).
# 4. Build/install pyOptSparse as instructed.
# Elizabeth Wong (
# 30 March 2020
import os,sys
def configuration(parent_package='',top_path=None):
from numpy.distutils.misc_util import Configuration
config = Configuration('pySNOPT', parent_package, top_path)
# Since snopt has a bunch of source files, we will just check if
# snoptc.c exists. If so, we will assume all the rest of the files
# are present.
#snoptc = os.path.join('pyoptsparse/pySNOPT/source', 'snoptc.f')
#if os.path.exists(snoptc):
# config.add_library('snopt', sources=[os.path.join('source', '*.f')])
# config.add_extension('snopt', sources=['source/f2py/snopt.pyf'],
# libraries=['snopt'])
# Edit SNOPT7 library path:
snopt7_path= '/path/to/SNOPT/library'
if os.path.exists(snopt7_path):
os.path.join('source', '*.f')],
return config
Copy link

pollinico commented Feb 3, 2021

Did you test it in Windows 10? I am trying to set up SNOPT ddl and lib in pyOptSparse by using this script but it fails the "python install" command. If you have suggestions on how to set up SNOPT dll in Windows for Python 3 they are more than welcome! Thanks!

Copy link

gnowzil commented Feb 8, 2021

What environment in windows are you using? I think in theory, this will work if you're in mingw/cygwin (64-bit), it should work. I can investigate if you can give me more details on your environment.

Copy link

pollinico commented Oct 11, 2021

Hi, I am in Windows 10 using Python 3 with Anaconda.
these are the files I have:

How can I set up pyOptSparse so that it is installed together with SNOPT?
Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment