stata_kernel icon indicating copy to clipboard operation
stata_kernel copied to clipboard

cannot import stata kernel

Open mikcaf opened this issue 4 years ago • 49 comments

Problem description

I do not know anything about programming, but my class requires me to use a jupyter notebook with stata kernel. When I run the command

pip install stata_kernel

on my terminal, the operation seems successful (I am even able to see the option on jupyter of using the stata kernel).

However, when I run my second command

python -m stata_kernel.install

The terminal says:

Cannot import kernel Installing Jupyter kernel spec

I am not sure if the issues are related, but when I go on jupyter and I try to use the stata kernel, it says connecting, but then after some time it just disconnects (it never says Stata|Idle).

Please, I need help because I need to start submitting assignments on jupyter notebook by Thursday but I cannot make this work!

  • Operating System: Big Sur
  • Stata version: 16.1
  • Package version: 1.12.2

mikcaf avatar Jan 05 '21 14:01 mikcaf

@mikcaf Can you run python -m jupyter --version and report the output?

mcaceresb avatar Jan 05 '21 14:01 mcaceresb

@mikcaf Can you run python -m jupyter --version and report the output?

jupyter core : 4.6.3 jupyter-notebook : 6.1.4 qtconsole : 4.7.7 ipython : 7.19.0 ipykernel : 5.3.4 jupyter client : 6.1.7 jupyter lab : 2.2.6 nbconvert : 6.0.7 ipywidgets : 7.5.1 nbformat : 5.0.8 traitlets : 5.0.5

mikcaf avatar Jan 05 '21 14:01 mikcaf

@mikcaf Interesting. What about jupyter kernelspec list?

Also, do you have Stata IC, SE, or MP?

Last, can you run, from Python, from jupyter_client.kernelspec import KernelSpecManager?

mcaceresb avatar Jan 05 '21 14:01 mcaceresb

@mcaceresb

When I run jupyter kernelspec list

I receive

Available kernels: stata /Users/MikCaf/Library/Jupyter/kernels/stata python3 /Users/MikCaf/opt/anaconda3/share/jupyter/kernels/python3

I have Stata IC

If I run: python jupyter_client.kernelspec import KernelSpecManager

I receive

python: can't open file 'jupyter_client.kernelspec': [Errno 2] No such file or directory

mikcaf avatar Jan 05 '21 15:01 mikcaf

@mikcaf Start python first, then from inside python run from jupyter_client.kernelspec import KernelSpecManager

mcaceresb avatar Jan 05 '21 15:01 mcaceresb

@mcaceresb

Sorry for my ignorance, but how exactly do I run Python? Again, I am a novice and I am desperately trying to install the kernel for a College class

mikcaf avatar Jan 05 '21 15:01 mikcaf

@mikcaf Type python and press enter.

mcaceresb avatar Jan 05 '21 15:01 mcaceresb

@mikcaf Can you also tell me your version of Python?

mcaceresb avatar Jan 05 '21 15:01 mcaceresb

@mcaceresb My version of Python is 3.8.5.

When I run on python from jupyter_client.kernelspec import KernelSpecManager Nothing happens(?).

If I run Python, it says Python 3.8.5 (default, Sep 4 2020, 02:22:02) [Clang 10.0.0 ] :: Anaconda, Inc. on darwin Type "help", "copyright", "credits" or "license" for more information.

Then I run:

from jupyter_client.kernelspec import KernelSpecManager

and I am back to this:

Does this help?

mikcaf avatar Jan 05 '21 15:01 mikcaf

@mikcaf You installed python via Anaconda? Can you try uninstalling Anaconda and reinstalling? If that doesn't do the trick let me know.

mcaceresb avatar Jan 05 '21 15:01 mcaceresb

@mcaceresb

I am not sure how I installed Python. By the way, I already uninstalled and re-installed Anaconda a couple of times and I get the same problem again. Should I be able to install the stata kernel even without Anaconda? Because if that is the case, I can tell you that without Anaconda I cannot even use the code:

pip install stata_kernel

mikcaf avatar Jan 05 '21 15:01 mikcaf

@mikcaf I see. You need Python for pip. Let's try this: Uninstall Anaconda and install Python via brew: brew install python. If you don't have brew, install it first: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Then try to install the kernel again.

mcaceresb avatar Jan 05 '21 15:01 mcaceresb

@mcaceresb For my class, I was asked to use and download Anaconda. Should I install the stata kernel before or after installing Anaconda? I guess my question is: after I install brew and python, should I also install Anaconda and then stata kernel, or can I go directly to stata kernel and then install Anaconda?

mikcaf avatar Jan 05 '21 16:01 mikcaf

@mikcaf While I also tend to recommend Anaconda, I want to figure out if for whatever reason it is clashing with the Stata kernel.

  • Uninstall Anaconda
  • Install brew
  • Install python via brew
  • Install the kernel
  • Check if the kernel works

Do not reinstall Anaconda yet.

mcaceresb avatar Jan 05 '21 16:01 mcaceresb

@mcaceresb I did the first 3 steps, but when I run pip install stata_kernel

I get: -bash: pip: command not found

mikcaf avatar Jan 05 '21 16:01 mikcaf

@mcaceresb

should I use pip3 as a command?

mikcaf avatar Jan 05 '21 16:01 mikcaf

@mikcaf If pip3 and python3 are available then yes, use those.

mcaceresb avatar Jan 05 '21 16:01 mcaceresb

@mcaceresb

After I run

pip3 install stata_kernel, I get:

Successfully built stata-kernel

when I run,

python3 stata_kernel.install

again I get: Cannot import kernel Installing Jupyter kernel spec

mikcaf avatar Jan 05 '21 16:01 mikcaf

@mcaceresb

sorry, I meant:

python3 -m stata_kernel.install

mikcaf avatar Jan 05 '21 16:01 mikcaf

@mcaceresb do you have any other idea?

mikcaf avatar Jan 05 '21 16:01 mikcaf

You could try downgrading from sur back to the previous osx version. If that is too much of a hassle then I'll need to think for a bit abt what else u could try.

mcaceresb avatar Jan 05 '21 16:01 mcaceresb

@mcaceresb I think this is probably related to the recent change here https://github.com/kylebarron/stata_kernel/commit/d436d9be8a94858ddbbb5853bfbbf0e852a41ff0#diff-989130b8db8fa5d0d5369619ecb45f2b72696aa855d481b5169c13157ab67b86R5-R8

hence the "Cannot import kernel". I think that block really needs to at least print the caught error...

try:
except error as e:
	print(e)
	print('cannot import kernel')

kylebarron avatar Jan 05 '21 16:01 kylebarron

@mikcaf Can you uninstall the kernel and reinstall the github version? It should print more detailed error information that might help debug.

pip3 install -U git+https://github.com/kylebarron/stata_kernel
python3 -m stata_kernel.install

mcaceresb avatar Jan 05 '21 20:01 mcaceresb

Hi, guys. I have the same problem: when I execute in Anconda's prompt

python -m stata_kernel.install

and I get

Cannot import kernel Installing Jupyter kernel spec

I follow your discussion and their possible solutions; when i'm trying to download the package from GitHub i have this result:

ERROR: Cannot unpack file C:\Users\hp\AppData\Local\Temp\pip-unpack-kc5x_ci6\stata_kernel (downloaded from C:\Users\hp\AppData\Local\Temp\pip-req-build-06gycg6x, content-type: text/html; charset=utf-8); cannot detect archive format ERROR: Cannot determine archive format of C:\Users\hp\AppData\Local\Temp\pip-req-build-06gycg6x

Windows 10 Home Single Languaje (intel core i3) Stata version: 16.1 MP Jupyter-notebook version: 6.1.4

Ayrton1931 avatar Feb 01 '21 21:02 Ayrton1931

@Ayrton1931 What did you run that gave you the error?

I follow your discussion and their possible solutions; when i'm trying to download the package from GitHub i have this result:

mcaceresb avatar Feb 01 '21 23:02 mcaceresb

Hi @mcaceresb, i run in anaconda's prompt:

python -m pip install https://github.com/kylebarron/stata_kernel

Ayrton1931 avatar Feb 02 '21 01:02 Ayrton1931

From above:

pip3 install -U git+https://github.com/kylebarron/stata_kernel
python3 -m stata_kernel.install

You need to copy/paste that link

kylebarron avatar Feb 02 '21 01:02 kylebarron

For anyone else facing this issue: After trying several times with different versions of Anaconda and Miniconda installers, I finally had success (following the standard steps on the "Getting Started" page) just using an older version of Miniconda (specifically, Miniconda3 py37_4.8.3). I don't know what the exact problem is, but note that the Miniconda installation page (https://docs.conda.io/en/latest/miniconda.html) only offers versions 2.7, 3.8, and 3.9 of Python, whereas the stata_kernel documentation explicitly states it works with Python versions 3.5, 3.6, and 3.7, so you need to locate an archived version of the installer (like the one I mentioned).

cocopops17 avatar May 13 '21 15:05 cocopops17

I don't think there's any reason why it shouldn't work with Python 3.8 or 3.9... The restriction in the metadata file is just 3.5+

https://github.com/kylebarron/stata_kernel/blob/ec3f51c2f4b2cf5469a53b7de06f9511ebd07ba4/setup.py#L57

kylebarron avatar May 13 '21 18:05 kylebarron

Yeah, to be clearer, I never received a message specifically about version incompatibility, just the same "Cannot import kernel" error as the previous commenters when trying to use "Miniconda3-py39_4.9.2" or "Anaconda3-2020.11". I have no idea why those newer installers weren't playing nicely.

cocopops17 avatar May 13 '21 19:05 cocopops17