can't import 'torchtext' module in jupyter notebook while using pytorch - jupyter-notebook

I installed pytorch using anaconda3 and my created virtual conda environment named 'torchTest'.
I installed all the modules needed but, codes doesn't work in jupyter python.
I installed torchtext using
1.pip install https://github.com/pytorch/text/archive/master.zip
2.and also pip install torchtext too.
all I mentioned successfully downloaded in my MAC OS X, but can't get what's wrong with my Jupyter notebook..

After having the same issue with torchtext from within my jupyterlab, I opened an issue on Github at the jupyterlab project as well as at the torchtext repository.
My current solution is to add the PYTHONPATH from the Anaconda env.
The Anaconda path is usually like that $HOME/anaconda/bin
You can add it from within Jupyter Lab/Notebook like that:
import sys
sys.path.append("/some/path/to/add")
import torchtext

Related

Manually install packages into ipykernel NOT with anaconda

So I want to avoid using anaconda. How can I download packages into an ipykernel I made? I have the location, I just don't know how to activate ipykernels. I see the option for making a new .ipynb file once I'm within the jupyter API but this doesn't help me add the libraries I want to keep isolated on my machine.
you can install packages inside jupyter note book by
!pip install pandas("Your package name")
in a cell and run it

Can't import tf2 into jupyter notecook

I have just installed tensorflow2, but when I open a jupyter notebook and import tensorflow, when I do print(tf.version) I get a 1.13 version.
If tf.__version__ gives you 1.13 is becase in the current environment you have TensorFlow 1.13 installed.
You can have a look at every package installed in the current environment by using pip freeze and looking at the list.
However, to be sure you are working in an environment where TensorFlow 2.0 is installed, you can create a virtualenv and install therein everything you need with pip.
Remember to install also the jupyter notebook package inside your virtual environment, otherwise you will execute the system jupyter notebook and it will load the TensorFlow package installed at system-level.
Hope it helps

Do I need to install Jupyter notebook in every virtual environment?

I isolate my data science projects into virtual environments using pipenv. However, running a Jupyter notebok does not access the local environment and uses the default IPyKernel. I've seen that you can register virtual environments from within the environment, but this requires installing the ipykernel package which itself requires Jupyter!
Is there anyway to avoid this and just use a single Jupyter install for all virtual environments?
Generally, you'd install jupyter once and do the following in your virtual environments:
pip install ipykernel
python -m ipykernel install --user
This isn't enough when you're running multiple Python versions.
There's a guide here that tries to address this:
https://medium.com/#henriquebastos/the-definitive-guide-to-setup-my-python-workspace-628d68552e14
It's not 100% failsafe, but it can help you avoid reinstalling jupyter notebook all the time.
I found that there are few problems when reinstall jupyter for each environment separately: i.e. pip install jupyter jupyterlab in new environments.
I had multiple issues (with and without Conda), where Jupyter would install packages to a different python environment when you use !pip install a_package_name within a cell. The shell environment still kept track of the non-environment python, and you can tell this by comparing the outputs of !which python and
import sys
sys.executable
Therefore, when you tried to import the package, it would not be available, because the cells used the environment python/ kernel (as it detected the venv directory).
I found a workaround that I'd appreciate feedback on. I changed pipenv to install virtual environments into the working directory by add to .bashrc/.bash_profile:
export PIPENV_VENV_IN_PROJECT=1
Now when opening a Jupyter notebook, I simply tack on the virtual environment's packages to the Python path:
import sys
sys.path.append('./.venv/lib/python3.7/site-packages/')
Is this a terrible idea?

rpy2 import works in shell but not in jupyter notebook

So, I have installed rpy2 successfully, and I can import it in a python shell, for example. Also, I have Jupyter notebook successfully installed. But for some reason I cannot import rpy2 on the jupyter notebook. I get the standard 'module not found' error. Other posts have addressed problems relating to installation of rpy2 itself, but specifically, I can't import ONLY from jupyter notebook. I find it quite strange, because I'm fairly certain I only have one copy of Python 3.6, so why can it import in the terminal but not in the notebook. .. .
I solved this by re-installing jupyter notebook. . .
I encountered the same issue, and I use many different env with conda. Here is my solution, starting your jupyter notebook with the same env which rpy2 is installed.

Using a Jupyter imported library?

Here is the big question:
Do i need to explicitly install a library, such as Plotly, in order for my locally hosted Notebook to import it?
Yes you need to have the library installed in your local environment to import it into your Jupyter Notebook.
However, you can check whether a package exists from within Jupyter Notebook and also automatically install it if it isn't already available.
you can run pip as well as shell commands from within a cell of the notebook
The syntax is as follows !pip install plotly Here the ! explicitly forces the kernel to execute the command.
If it's already installed you'll get this message Requirement already satisfied: plotly in /opt/conda/lib/python2.7/site-packages

Resources