Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: module 'networkx' has no attribute 'connected_component_subgraphs' #25

Open
u7390 opened this issue Nov 26, 2022 · 12 comments

Comments

@u7390
Copy link

u7390 commented Nov 26, 2022

I read #21 .
Doing
pip install --force-reinstall networkx==2.3
on Command Prompt for Windows operating system and Terminal on Linux operating system does not solve the problem when using it as a plugin for QGIS Desktop software.

@u7390
Copy link
Author

u7390 commented Nov 26, 2022

The following images show what I did with red lines going around the button I clicked. If there is more than 1 line going around, there is number on the left showing the order it was clicked.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

@MgTheProgrammer
Copy link

experiencing the same on macOS🥲

@MgTheProgrammer
Copy link

experiencing the same on macOS🥲

turns out unlike I've read somewhere qgis does install it's own python interpter. I've run pip install --force-reinstall networkx==2.3 on the pip of the qgis python installation and got one step further!

I did encounter another issue though but thankfully it was an easy fix. qgis comes with python3.9 which has moved some function called gcd from a module named fractions to math. I've changed in a file named dag.py from fractions import gcd to from math import gcd and it seems like everything works now.

@michael-ts
Copy link

@MgTheProgrammer How did you run the QGIS version of PIP? I tried running in from a Windows command prompt in the directory that pip.exe is installed in under QGIS, but get a fatal python error and no module named encodings.

@michael-ts
Copy link

michael-ts commented Dec 25, 2022

@MgTheProgrammer I also tried:

import pip
pip.main(['install', '--force-reinstall', 'networkx==2.3'])

But got tons of errors. Next I tried:

pip.main(['install', '--force-reinstall networkx==2.3'])

But this crashes QGIS (I opened, re-ran the import and called it again and it crashes every time)

Another thing I tried was running this from the QGIS python directory:

python -m pip install --force-reinstall networkx==2.3

But this failed with a message pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available following which it failed to download anything due to the missing ssl module.

@MgTheProgrammer
Copy link

@michael-ts
Sadly I don't quite remember what I did. I imagine though that I ran pip using its directory (on Mac it probably looked like that:
/Applications/QGIS.app/Contents/MacOS/bin/pip3 install networkx==2.3).

I opened qgis now as you reminded me about this. And weirdly enough it doesn't work correctly, it gives me a path and concludes that its length is 0 km. I'm pretty sure last time I've played with it, it worked though. So I guess it's more related to something wrong with the input I give from qgis.

@MgTheProgrammer
Copy link

Btw if what you are looking for is mostly an optimized route and less about specifically using it with qgis. This repo works without much effort from you as a user. It does give a bit less control but it's good enough imo.

@michael-ts
Copy link

@MgTheProgrammer Thanks, I'm looking at this and it looks like it might be helpful at least until I can figure out how to get the QGIS plug-in working. I noticed a couple of issues which using QGIS may or may not solve:

  1. I accidentally deleted a segment in the middle of a road I wanted to follow (not sure why; apparently it tries to find the closest segment to the mouse and despite the segment it deleted being some distance away it must have been the closest) and couldn't figure out how to add it back, so all the clicking I had done so far was wasted. It seems to be a LOT of clicking as there are lots of tiny line segments making up a single stretch of road.

  2. There doesn't seem to be any way of specifying that you can take a segment if needed, but don't have to. In this case I had two disconnected networks of roads I wanted to reach in one trip, and it would be nice if it could find them minimal distance way to get between the two. But as soon as I the two networks became disconnected, the one not attached to my starting point was automatically erased.

@michael-ts
Copy link

@MgTheProgrammer Also, it seems to be brute-forcing the solution. I thought there was a polynomial time solution; this isn't the travelling salesman problem...

@michael-ts
Copy link

@MgTheProgrammer It's also not clear to me how to find the actual route... I downloaded the GPX file (was the only option offered). I tried to download it into Google Maps but it claimed (wrongly) that the GPX file was bad. I found a GPX to KML convertor but when I look at the route on the map it shows all the streets reached but I can't tell in what order to visit them. I found an online GPX editor and I can tell the route but only by dragging a slider and this would be a pain to try to manually transcribe into something like turn by turn directions. What method do you use?

@u7390
Copy link
Author

u7390 commented Mar 5, 2023

This is how I make the plugin work on a newly installed Fedora Workstation that have been updated, and have its graphic driver and related software installed.

After opening , I install the plugin.
f1

f2

f3

f4

f5

f6

f7

I somehow see the information about error.
f8

f9

I do something to pip.
pip install --upgrade pip
f10

f11

pip install --force-reinstall networkx==2.3
f12

f13

This is how i run QGIS Desktop.
f14

f15

f16

f17

I see there is still error and click there to see more information.
f18

f19

I can see above the line mentioning the Python version an error. Above that error I see it says it is in a file called dag.py in line 23.
f20

I click on the option to show hidden files and then go to that file so I can edit it.
f21

f22

f23

f24

f25

f26

f27

I click on the thing to shows the line number..
f28

f29

f30

I change the writing in line 23 to
from math import gcd
f31

I click on the thing that looks the letter x on the top right.
f32

f33

I run QGIS Desktop again and see that error is gone.
f34

f35

I click that so the hidden file is not shown anymore.
f36

f37

@jarvena
Copy link

jarvena commented Mar 21, 2023

Following modification to postman.py also fixes the error. nx.connected_component_subgraphs() is deprecated, thus causing the error.

def graph_components(graph):
    # The graph may contain multiple components, but we can only handle one connected component. If the graph contains
    # more than one connected component, we only use the largest one.
    components = list((graph.subgraph(c) for c in nx.connected_components(graph))) #list(nx.connected_component_subgraphs(graph)) <-- this is deprecated
    components.sort(key=lambda c: c.size(), reverse=True)

    return components

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants