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

Windows paths #4

Open
maxim1317 opened this issue Aug 11, 2020 · 4 comments
Open

Windows paths #4

maxim1317 opened this issue Aug 11, 2020 · 4 comments

Comments

@maxim1317
Copy link

sf.load_network() Fails to work with windows paths in ini file:

re.sub crashes in load_network_from_gpickle from safe_io.py
I think it's due to path concatenation or escaping error

Try using pathlib

@maxim1317 maxim1317 reopened this Aug 11, 2020
@abarysh
Copy link
Contributor

abarysh commented Aug 12, 2020

Hi Maxim, thanks a lot for the bug report. Would you be able to send upload your ini file? Or an example of the path you're using?

@EdoardoGerva
Copy link

Hi Anastasia, I am also trying to run SAFE in a Windows OS. I think the problem here is about file paths: several functions in safe_io.py call files as they were in a Linux environment, using "~" to call the User Home Directory for instance, and this is not directly extendable also to a Windows environment. What do you think?

@abarysh
Copy link
Contributor

abarysh commented Jun 23, 2023

Hi Edoardo, thanks for the comment! Unfortunately, I don't have a Windows machine to test this out. But my understanding is that expanduser("~") should work on both Unix and Windows (https://www.geeksforgeeks.org/python-os-path-expanduser-method/) and replace "~" with the corresponding home directory. Could you share a more specific description of the error you're getting? Thank you.

@EdoardoGerva
Copy link

EdoardoGerva commented Jun 28, 2023

Actually I am not sure "~" is the only problem. Here I can show you my error message, maybe it can help you:

Loading network from (my path to folder)/ISN/safe-data/networks/Costanzo_Science_2016.gpickle
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
File ~\anaconda3\lib\sre_parse.py:1039, in parse_template(source, state)
   1038 try:
-> 1039     this = chr(ESCAPES[this][1])
   1040 except KeyError:

KeyError: '\\U'

During handling of the above exception, another exception occurred:

error                                     Traceback (most recent call last)
Cell In [3], line 1
----> 1 sf.load_network()

File ~/Desktop/Lavoro/Leuven/ISN/safepy\safe.py:258, in SAFE.load_network(self, **kwargs)
    256     self.graph = load_network_from_mat(self.path_to_network_file, verbose=self.verbose)
    257 elif file_extension == '.gpickle':
--> 258     self.graph = load_network_from_gpickle(self.path_to_network_file, verbose=self.verbose)
    259 elif file_extension == '.txt':
    260     self.graph = load_network_from_txt(self.path_to_network_file,
    261                                        node_key_attribute=self.node_key_attribute,
    262                                        verbose=self.verbose)

File ~/Desktop/Lavoro/Leuven/ISN/safepy\safe_io.py:95, in load_network_from_gpickle(filename, verbose)
     93 def load_network_from_gpickle(filename, verbose=True):
---> 95     filename = re.sub('~', expanduser('~'), filename)
     96     G = nx.read_gpickle(filename)
     98     return G

File ~\anaconda3\lib\re.py:210, in sub(pattern, repl, string, count, flags)
    203 def sub(pattern, repl, string, count=0, flags=0):
    204     """Return the string obtained by replacing the leftmost
    205     non-overlapping occurrences of the pattern in string by the
    206     replacement repl.  repl can be either a string or a callable;
    207     if a string, backslash escapes in it are processed.  If it is
    208     a callable, it's passed the Match object and must return
    209     a replacement string to be used."""
--> 210     return _compile(pattern, flags).sub(repl, string, count)

File ~\anaconda3\lib\re.py:327, in _subx(pattern, template)
    325 def _subx(pattern, template):
    326     # internal: Pattern.sub/subn implementation helper
--> 327     template = _compile_repl(template, pattern)
    328     if not template[0] and len(template[1]) == 1:
    329         # literal replacement
    330         return template[1][0]

File ~\anaconda3\lib\re.py:318, in _compile_repl(repl, pattern)
    315 @functools.lru_cache(_MAXCACHE)
    316 def _compile_repl(repl, pattern):
    317     # internal: compile replacement pattern
--> 318     return sre_parse.parse_template(repl, pattern)

File ~\anaconda3\lib\sre_parse.py:1042, in parse_template(source, state)
   1040         except KeyError:
   1041             if c in ASCIILETTERS:
-> 1042                 raise s.error('bad escape %s' % this, len(this))
   1043         lappend(this)
   1044 else:

error: bad escape \U at position 2

May it also be related to the use of forward slashes / instead of backslashes \?

kjaeyoun added a commit to kjaeyoun/safepy that referenced this issue Feb 25, 2024
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

3 participants