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

Unable to use resources.get_controller() function #226

Open
Tama-sha opened this issue Mar 10, 2023 · 6 comments
Open

Unable to use resources.get_controller() function #226

Tama-sha opened this issue Mar 10, 2023 · 6 comments
Assignees
Labels
question User requires information

Comments

@Tama-sha
Copy link

Tama-sha commented Mar 10, 2023

Steps used:
from pypath import resources
rc = resources.get_controller()
rc

Error:
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 40814: character maps to

Complete snapshot:
image

Additional query:
I wanted to create a network from resources available for commercial use but i am not able to obtain the correct function either

@Tama-sha Tama-sha added the bug Problem in the code label Mar 10, 2023
@deeenes
Copy link
Member

deeenes commented Mar 10, 2023

Hello @Tama-sha, The reason of this error is that your operating system's default character encoding is code page 1252, while the resources.json file distributed with pypath is UTF-8 encoded, as it is more or less a standard practice today. The solution is to run your Python interpreter with UTF-8 default encoding.

@deeenes deeenes self-assigned this Mar 10, 2023
@deeenes deeenes added question User requires information and removed bug Problem in the code labels Mar 10, 2023
@deeenes
Copy link
Member

deeenes commented Mar 10, 2023

About your other question, I checked the current state of license parameters in pypath, and I filled a few gaps to make it better usable in the database build process. Due to these recent developments, you'll need to update pypath from the git master branch (version should be >=0.14.38). I also added a little section to the Pypath book to show you how does it work. I hope this helps, please let me know if you have any question.

@Tama-sha
Copy link
Author

About your other question, I checked the current state of license parameters in pypath, and I filled a few gaps to make it better usable in the database build process. Due to these recent developments, you'll need to update pypath from the git master branch (version should be >=0.14.38). I also added a little section to the Pypath book to show you how does it work. I hope this helps, please let me know if you have any question.

image
Hi @deeenes thank you so much for your swift reply but seems like i caught myself in another issue after updating the pypath version. Now the first sample commands in the pypath book are not working. I am sorry but i am a novice

@Tama-sha
Copy link
Author

Hello @Tama-sha, The reason of this error is that your operating system's default character encoding is code page 1252, while the resources.json file distributed with pypath is UTF-8 encoded, as it is more or less a standard practice today. The solution is to run your Python interpreter with UTF-8 default encoding.

Hi @deeenes i also tried to see the default encoding
I tried to find the default encoding using:
import sys
encoding = sys.getdefaultencoding()
print(encoding)
The output was:
utf-8

@deeenes
Copy link
Member

deeenes commented Mar 13, 2023

I'll look into this soon, but just as a quick note, your screenshots are so small that I can not read them. You could instead just copy-paste the error and traceback as text, directly into your comments here. You can enclose it between triple backticks for proper formatting: ``` ...insert your multi-line code/output here... ```.

About the encodings: apparently Python uses cp1252 encoding when reading files, we have to find out why. As the built-in Python 3 json module should always use UTF-8 as default, maybe Miniconda or some of your RC files modifies the default settings. The easiest way to reproduce the error is the following:

import json

path = '~\AppData\Local\Continuum\Miniconda3\lib/site-packages\pypath\resources\data\resources.json'
with open(path, 'r') as fp:
  resources = json.load(fp)

Then you can see if it fails, and you can check the encoding of fp:

fp
<_io.TextIOWrapper name='pypath/resources/data/resources.json' mode='r' encoding='UTF-8'>

Also, you could try to set the LC_CTYPE environment variable in PowerShell and then start Python and test the thing:

setx LC_CTYPE 'UTF-8'
python

Or set the variable in Cygwin Bash and start Python:

export LC_CTYPE='UTF-8'
python

However, we can also explicitly enforce the UTF-8 encoding in pypath, I will soon commit a patch for that. This will likely resolve your issue.

@Tama-sha
Copy link
Author

Hi @deeenes
I apologize for the screenshot quality.
The error i am getting after updating after updating the version to 0.14.38

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[1], line 3
      1 import locale
      2 locale.setlocale( locale.LC_ALL, 'en_US.UTF-8' )
----> 3 from pypath import resources
      4 rc = resources.get_controller()
      5 rc

File ~\AppData\Local\Continuum\miniconda3\lib\site-packages\pypath\resources\__init__.py:25
      1 #!/usr/bin/env python
      2 # -*- coding: utf-8 -*-
      3 
   (...)
     22 #  Website: http://pypath.omnipathdb.org/
     23 #
---> 25 from . import controller as _controller_mod
     28 def get_controller(reload = False):
     29     """
     30     Returns the resource controller.
     31 
     32     The controller instantiated only once by default, at the first access
     33     attempt. The instance is stored in the module and provided on demand.
     34     """

File ~\AppData\Local\Continuum\miniconda3\lib\site-packages\pypath\resources\controller.py:42
     39 import itertools
     41 import pypath.share.session as session_mod
---> 42 import pypath.share.common as common
     43 import pypath.internals.resource as resource_base
     44 import pypath.resources.network as netres

File ~\AppData\Local\Continuum\miniconda3\lib\site-packages\pypath\share\common.py:2643
   2635     """
   2636     Nest multiple functions into a single function.
   2637     """
   2639     return lambda x: functools.reduce(lambda x, f: f(x), (x,) + funcs)
   2642 def compr(
-> 2643         obj: Iterable | dict,
   2644         apply: Callable | None = None,
   2645         filter: Callable | None = None,
   2646     ) -> Iterable | dict:
   2647     """
   2648     Unified interface for list, dict, set and tuple comprehensions.
   2649 
   (...)
   2661         Same type as the input: a list, a dict or a set or a tuple.
   2662     """
   2664     _type = (
   2665         dict
   2666             if isinstance(obj, Mapping) else
   (...)
   2669         list
   2670     )

TypeError: unsupported operand type(s) for |: '_SpecialGenericAlias' and 'type'

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

No branches or pull requests

2 participants