No module named 'torch' in Jupyter Notebook but it is installed (Mac OS) - macos

So when I try to import torch in jupyter notebook it gives the error no module named 'torch'.
I created a conda environment named "Thesis" where I work in and install my packages.
When I try these commands in my terminal it says the package is installed (see three images below):
torch1
torch2
torch3
I tried many commands to install the package:
pip install torchvision
python3 -m pip install torchvision
conda install pytorch torchvision -c pytorch
I also tried installing the package directly in the jupyter notebook itself via:
import sys
!{sys.executable} -m pip install torchvision
It at least shows something but I got the following dependency error
dependency error
I also created a kernel
ipython kernel install --name "thesis" --user
All did not help and I still receive the error in jupyter notebook.
Does somebody know how to resolve this?

I solved the problem by downloading and activating virtualenv with:
python3 -m pip install virtualenv
virtualenv <my_env_name>
source <my_env_name>/bin/activate
And getting the path in the jupyter notebook by:
import sys
print(sys.executable)
which outputs:
/Users/{username}/opt/anaconda3/bin/python
And installing the packages in the terminal via:
/Users/{username}/opt/anaconda3/bin/python -m pip install {package_name}

Related

pip installing matplotlib but while importing showing error message: "DLL load failed while importing _path: %1 is not a valid Win32 application."

Solve the following issue
tried different installation method like
pip, pip2, pip3
or
Update pip
python -m pip install -U pip
Install scikit-image
python -m pip install -U matplotlib

ModuleNotFoundError: No module named 'reportlab'

I have tried:
pip install report lab
pip install --upgrade --force-reinstall reportlab;
but still reportlab cannot be recognised with pycharm but it's already imported via PIP as below
Use this command instead:
pip install reportlab
Also if you are using an "virtual enviroment" then that is causing the problem.
If you are using pycharm then,
Use this command in pycharm's terminal:
pip install reportlab

How can I install a local Python package into an Anaconda environment?

How can I install a local Python package (.whl) into an Anaconda environment?
I solved this problem the following way:
If you have a non-conda pip as your default pip but conda python is your default python (as below)
>which -a pip
/home/<user>/.local/bin/pip
/home/<user>/.conda/envs/newenv/bin/pip
/usr/bin/pip
>which -a python
/home/<user>/.conda/envs/newenv/bin/python
/usr/bin/python
Then instead of just calling pip install , you can use the module flag -m with python so that it uses the anaconda python for the installation
python -m pip install
This installs the package to the anaconda library directory rather than to the library directory associated with (the non-anaconda) pip

how to install fastai on windows 10

I cant seem to install the right version of torch and I cant get fast ai libraries working
I try
Python 3.7
pip3 install https://download.pytorch.org/whl/cu100/torch-1.0.1-cp37-cp37m-win_amd64.whl
pip3 install torchvision
Could not find a version that satisfies the requirement torch>=1.1.0 (from torchvision) (from versions: 0.1.2, 0.1.2.post1, 0.1.2.post2)
No matching distribution found for torch>=1.1.0 (from torchvision)
I feel like I may of downgraded my gpu when I tried conda install fast ai
and then I tried pip and it couldnt find a file C:\Users\Admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\caffe2\python\serialized_test\data\operator_test
I finally got to the point where it said successfully installed six, pillow, and torch but torch is at 0.3 which is incompatiable.
pip3 install https://download.pytorch.org/whl/cu100/torch-1.0.1-cp37-cp37m-win_amd64.whl
pip3 install torchvision
expected to install pytorch or fastai nothing seems to work
You may try installing the course by creating a conda environment provided anaconda is already installed in your windows machine.
conda update conda
conda create -n fastai_conda python=3.6
conda activate fastai_conda
conda install fastai pytorch=1.0.0 -c fastai -c pytorch -c conda-forge
Or for installing CPU version you can use the below commands after the environment is created
conda install -c pytorch pytorch-cpu torchvision
conda install -c fastai fastai
You can check if installation went right with this command
python -m fastai.utils.show_install
You may further need to install ipykernel to use the conda environment in your jupyter notebook.For that activate environment and run the following commands:
conda install nb_conda_kernels
python -m ipykernel install --user --name fastai_v1 --display-name "fastai v1"
conda install ipywidgets

Cannot install jupyter notebook

In windows 7, I try to install jupyter notebook using:
pip3 install jupyter
But I get error:
Command "python setup.py egg_info" failed with error code 1 in C:\Users\AppData\Local\Temp\pip-build-5in28fbw\pywinpty\
Best thing to do is to install Anaconda here
It includes its own "conda" terminal window for "windows", which will make it a lot easier for you to invoke jupiter notebook from the conda terminal, regardless of which folder you are in
First update if using linux system:
sudo apt-get update
sudo apt-get upgrade
Restart the system and try below steps:
Installing Jupyter with pip
As an existing or experienced Python user, you may wish to install Jupyter using Python’s package manager, pip, instead of Anaconda.
If you have Python 3 installed (which is recommended):
sudo python3 -m pip install --upgrade pip
sudo python3 -m pip install jupyter
If you have Python 2 installed:
sudo python -m pip install --upgrade pip
sudo python -m pip install jupyter
Congratulations, you have installed Jupyter Notebook! To run the notebook, run the following command at the Terminal (Mac/Linux) or Command Prompt (Windows Run CMD in Admin):
jupyter notebook
Update your setuptools and pip first then retry:
pip install --upgrade setuptools pip

Resources