1

I am running the first lines of the cell types notebook:

sweep_number = 30
sweep_data = data_set.get_sweep(sweep_number)

And I get this error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-8-1ff88b13fc24> in <module>()
      4 
      5 sweep_number = 30
----> 6 sweep_data = data_set.get_sweep(sweep_number)
      7 

C:\ProgramData\Anaconda3\lib\site-packages\allensdk\core\nwb_data_set.py in get_sweep(self, sweep_number)
    112                 unit = stimulus_dataset.attrs["unit"]
    113                 unit_str = None
--> 114                 if unit.startswith('A'):
    115                     unit_str = "Amps"
    116                 elif unit.startswith('V'):

TypeError: startswith first arg must be bytes or a tuple of bytes, not str
m00am
  • 5,910
  • 11
  • 53
  • 69
SaMa
  • 13
  • 2
  • Welcome to SO. I added a link to the notebook to your question and added the python tag since this might be a python problem, not one specific to allensdk. – m00am Mar 04 '18 at 09:25
  • The answer from @m00am is correct. This py2/py3 incompatibility was resolved on the master branch of allensdk a couple weeks ago: https://github.com/AllenInstitute/AllenSDK/issues/128. The fix will be included in the next point release. – davidf Mar 04 '18 at 18:43
  • @davidf thank you. can I clone the updated repo to the folder that was created when I installed through conda (i.e. ~\Anaconda3\Lib\site-packages\allensdk)? or this will mess up the installation? what is your advice if I want to be updated by the repo update and not wait for the next point release? – SaMa Mar 05 '18 at 20:13
  • @sMa You should uninstall your current build: `pip uninstall allensdk` Then install it from GitHub: `$ git clone https://github.com/AllenInstitute/AllenSDK.git` and: `$ pip install AllenSDK/` Sorry, having some formatting issues. – davidf Mar 06 '18 at 03:10

1 Answers1

1

The error you see is caused by the fact that the unit variable is a bytes literal and allensdk is trying to call endswith using a string on it. This cannot work, but that is not your fault. This is a common error when migrating from Python 2 to Python 3 (which introduced the bytes type; for detail see here). I would guess that you are running Python 3 and that causes the error, since allensdk cannot work with bytes here.

To work around this you either have to install Python 2, since you are using conda, create an environment that uses Python 2. This can be done as follows:

> conda create -n py2allen python=2.7
> activate py2allen
(py2allen)> pip install allensdk
(py2allen)> jupyter notebook

More information can be found here. If some of the requirements are not found, you can try to install them manually.

m00am
  • 5,910
  • 11
  • 53
  • 69
  • Thanks for your answer. I resolved the issue by adding a line to the script to change the byte to string: unit = unit.astype(str). Now I understand that creating an environment with python 2 is a better solution. – SaMa Mar 05 '18 at 20:03