alarm-redist / redist

Simulation methods for legislative redistricting.
https://alarm-redist.github.io/redist/
GNU General Public License v2.0
67 stars 23 forks source link

enumpart not recognizing networkx #101

Closed hamiltonw closed 3 years ago

hamiltonw commented 3 years ago

I'm running into some issues with the redist package, and I think they all stem from R isn't recognizing networkx. As an example, the code

library(redist) data(iowa) dir.create("./enumerated/") test1 <- redist.enumpart(redist.adjacency(iowa), "./enumerated/iowa_output_unordered", "./enumerated/iowa_output_ordered", "./enumerated/iowa_output_districts", ndists = 2 )

will result in

Traceback (most recent call last): File "/Library/Frameworks/R.framework/Versions/4.1/Resources/library/redist/python/ndscut.py", line 8, in <module> import networkx as nx ModuleNotFoundError: No module named 'networkx' Error: './enumerated/iowa_output_districts.dat' does not exist in current working directory.

Manually creating "./enumerated/iowa_output_districts.dat" and rerunning gives

Traceback (most recent call last): File "/Library/Frameworks/R.framework/Versions/4.1/Resources/library/redist/python/ndscut.py", line 8, in <module> import networkx as nx ModuleNotFoundError: No module named 'networkx'

but now "./enumerated/iowa_output_districts.dat" is a 222x2 array.

I've reinstalled networkx using pip, and then again within R using

library(reticulate) py_install("networkx")

but neither has worked to fix redist not recognizing networkx. Let me know if there's something I'm not doing correctly, and otherwise if there's anything else I can provide.

christopherkenny commented 3 years ago

Do you have python installed on your system or is reticulate using a conda environment?

christopherkenny commented 3 years ago

You may also want to set init = TRUE for your first time running redist.enumpat(), if you haven't run redist.init.enumpart() since your install of the package.

hamiltonw commented 3 years ago

Setting init=TRUE did the trick, thanks for the quick response.