Jupyter doesn't work when "setup.py" is used - python

I tried to install Jupyter on my Mac (10.9).
Since I'm using a computer at the university and don't have permission to write in /usr/local/bin, I downloaded Ipython from GitHub and typed python3.4 setup.py install --user on Terminal.
Though I didn't get any error while installing, Jupyter does not launch when I type ipython notebook (ipython3 notebook or jupyter were the same) and I got command not found error.
(I also tried to install via pip. However, pip does not work on my computer and I couldn't activate it using ensurepip.)

Why does pip not work? (insufficient privileges to write into system packages)?
Have you tried a virtual environments Creation of virtual environments? They are very useful for managing your environment so that you have local packages and a local bin folder for things like ipython:
$ python3 -m venv my_venv
$ source my_venv/bin/activate
$ pip install ipython[all]
This will install into your my_venv environment.

Related

Python virtual environment not installing packages in correct directory (python)

I have set up a virtual environment correctly have activated it and when I do "which python" it tells me the correct directory, but when I do pip install in the venv it installs the package in the default directory of the mac and not in my venv. I have tried using pycharm and installing packages with that, but it happens the same thing.
Edit:
Following I will do a walkthru of my steps, first I did python3 -m venv /path/to/new/virtual/environment, then I did source env/bin/activate, then I did which python and I got the intended directory, afterwards I did pip3 install numpy and I saw the installation process, then I did pip list and numpy was not there, I checked the directory manually and it still was not there. I retried all the same thing with pycharm with the same results.
Follow these steps in order -
In your current working directory :
python3 -m venv venv
source venv/bin/activate
(venv) pip3 install library_name
To check if libraries were properly installed or not :
(venv) pip3 freeze
and check if your installed libraries is displayed on the terminal screen or not.
To deactivate the virtual environment :
(venv) deactivate
This is due to permission issues
Run this command to change permission of your virtual environment folder
sudo chmod -R 777 venv
After activating your virtual environment
source venv/bin/activate
Then try to install Django by either Python3 or Python2
pip3 install django or pip install django
Then check the list of installed packages by either Python3 or Python2
pip3 list or pip list
NOTE: If you run sudo pip3 install django or pip install in virtual environment that is not writeable by default it will be installed outside of virtual environment
If you run pip3 install django or pip install in virtual environment that is not writtable by default it will be installed outside of virtual environment you will get OS Persmission Error
I have used pip3 and pip because you can install packages by either Python3 or Python2, thing to remember if you created virtual environment by Python3, use pip3 and if you created by using Python2 use pip.

How to make Jupyter Notebook import packages in Python3.5

I have several packages being imported perfectly in my Python 3.5. But not in my Jupyter Notebook... When i try to Import those packages in Jupyter i get and error of module not found.
Is there a way to make Jupyter load my Python 3.5 as a kernel... or something similar. I'm working in a virtual environment. Already tried to reinstall the packages again in my virtual env But no success.
Try to install the packages inside a jupyter notebook cell like this:
!pip install package
So you are sure that the packages are installed in jupyter's environment
If you install the ipython kernel form inside the virtualenv, you can guarantee that the packages are imported to the jupyter if they are imported to this env. Also, if you use this approach, you do not need to activate the virtualenv every time you run the jupyter, because jupyter does it automatically.
$ python -m venv projectname
$ source projectname/bin/activate
(venv) $ pip install ipykernel
(venv) $ ipython kernel install --user --name=projectname
(venv) $ pip install {package needed to install}
Source: Using jupyter notebooks with a virtual environment

Trying to install a pip package in Anaconda

I'm trying to follow this tutorial:
https://learn.microsoft.com/en-us/azure/machine-learning/service/tutorial-data-prep
As part of this I'm trying to do a pip install of azureml as it's not available on conda. However doing a pip install will by default install it to my default python install, and not my conda install.
So I tried following the steps here:
https://conda.io/docs/user-guide/tasks/manage-environments.html#using-pip-in-an-environment
However after following these steps I then launch Jupyter notebook after activating myenv, navigate to the notebook, and try and run:
import azureml.dataprep as dprep
But get the error: ModuleNotFoundError: No module named 'azureml'
Also - I cannot tell if myenv is active in the notebook. The kernel simply says python3.
Be careful, when using pip in anaconda, it is possible that you are mixing pip and pip3.
Run which pip3 to be sure you are using the version that correspond to the virtual environment.
If you are using python3 in the environment, then pip will typically be the correct version to use. Do not use pip3 in that case.
This problem has been documented elsewhere on the web. The problem is that Jupyter notebooks itself only launches in the root environment by default. The simplest solution to getting it to launch for your env (e.g. myenv) is to install Jupyter within your env first. So from the Anaconda command prompt:
activate myenv
pip install jupyter
jupyter
Ps. Use source activate myenv for non-windows machines

How to link virutualenvwrapper with Jupyter notebook

I have a venv/virtualenvwrapper set up in a directory. After I start working on the venv, i then create a Jupyter notebook inside of the directory, which brings me to Jupyter's localhost browser. I then attempt to import a library, e.g. pandas, which raises the ModuleNotFoundError. I would think that if the venv is being worked on, Jupyter would link to it.
Also, I can import global libraries from pip3, just not the local ones in a venv. Is there a way to use the virtualenvwrapper library with Jupyter?
I found out here I had to install ipykernel after activating the venv, then create a projectname:
​(venv) $ pip install ipykernel
(venv) $ ipython kernel install --user --name=projectname
​
After that, I went back to the Jupyter browser and change the kernel from python 3 to the projectname which is only viewable after executing the second command line above.
This works for both virtualenv and virutalenvwrapper.
The only downfall is installing ipykernel adds a lot of extra libraries to your venv pip3, but I suppose you could just install ipykernel in your global pip3 to keep from installing it in your venv.

Running jupyter notebook in a virtualenv (with permission issue)

I am trying to run jupyter notebook in a virtualenv on a cloud computing platform running Linux, but I am unable to install a ipykernel for jupyter notebook.
Here are the steps that I have done:
Install a virtual environment for python 3 at my local storage space. The tag --system-site-packages has been used, to minimize the size of the virtual environment folder. So it should inherit the global python 3.6 and libraries.
Activated the virtual environment, installed sympy, started python3, import sympy and it worked. (Note that without the virtualenv, pip does not work as we have no permission to write to the global version of python)
Tried to run jupyter notebook in the same virtual environment, but trying to import sympy returns No module named 'sympy'. Using print(sys.executable) reveals that it is running on the global python3.6. (When running python3 in virtualenv and printing executable, it prints the path of python3 in myvirtualenv/bin/python3)
Tried to follow these instructions. pip install jupyter and pip install ipykernel worked properly, saying requirement already satisfied. But python -m ipykernel install --user --name testenv --display-name "MyEnv" does not work, returning
[Errno 13] Permission denied: '/tmp/tmpc2ebdyp9_kernels/python3/kernel.json'
Perhaps you want `sudo` or `--user`?
which really confuses me, as I thought the --user tag should make it install at my local directory already. I also tried specifying the path of my virtualenv by using --prefix, but it is still saying I have no permission to access the system's kernel.json.
I also tried ipython kernel install --name "xx" --user and specifying path with --prefix but it returns the same error.
So my question is:
Did this error arise because even though the ipython kernel was installed locally, the kernel.json at the system directory still needs to be changed? Or did the tags --user or --prefix not work for some reason?
How can I create a kernel truly locally? I suppose after that I can create my own kernel.json as in here or here to direct the jupyter notebook to use my own kernel?
Thanks a lot in advance!

Categories

Resources