0

I want to use use both python 2.7 and 3.x in jupyter. so I create python 2.7 kernel. but I can't import several libraries like numpy, matplotlib, scipy and so on in jupyter. then I installed a lot of libraries in python 2.7 kernel. I think it's so terrible idea. are there any idea to solve my problem??

2
  • How did you install Jupyter? With Anaconda? Or did you just install Jupyter itself? Commented Nov 25, 2017 at 5:28
  • I install it as Anaconda Commented Nov 25, 2017 at 6:50

1 Answer 1

1

Obviously you can only use from within a specific kernel the libraries that that kernel has available so if you are trying to do the same basic things you need to have the same set of libraries available.

One trick that can help to shortcut this process is:

On Windows:

py -3 -m pip freeze > liblist.txt 

Will give you a list of the current pip installed libraries, with versions, in Python 3 so review the contents and delete the lines containing any that you probably don't need then, it is probably also worth stripping the ==version from each line:

py -2 -m pip install -r liblist.txt 

Should install them for you. If you add the --user flag your libraries will be added to the user space which may save some permissions problems.

On OS-X/Linux you can do the same but need to use python3 and python2 rather than py -3 & py -2 and if you do not use the --user flag you are likely to have to start the second command with sudo python2 rather than py -2 and then enter the password when prompted.

Sign up to request clarification or add additional context in comments.

3 Comments

thank you a lot. your answer is what I want. but I don't have a program like both py -3 and py -2. so I tried that "python -m list > liblist.txt and I ran virtualenv (activate activate ipykernel_py2). and then I tried this (pip install -r liblist.txt). sadly I think contents in liblist.txt are not compatible with pip command.
When you installed python 3, if you are on windows, it should have installed py for you. If you add --format=freeze to the pip list, or use pip freeze it will try for all of the same versions, (these might not be available so you can strip everything after - on each line).
thank you so much!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! I eventually solved my problem

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.