Cannot import torch in jupyterLab - import

Cannot import torch in jupyterLab.
It shows:
ImportError: cannot import name 'classproperty' from 'torch._utils'
But it works in my Anaconda prompt.
Thanks in advance.

Related

Python pillow module not importing properly

I'm using the Python pillow module, but every time I try to import it and use a function, it gives me an error. Here is some code to reproduce the error.
import PIL
PIL.ImageGrab.grab()
You have to use from to import from PIL.
from PIL import ImageGrab
ImageGrab.grab()

ImportError: cannot import name 'RoboBrowser' from 'robobrowser'

I am very new to Python and have used BeautifulSoup to parse and scrape information from some webpages. Now I need to fill out a form. submit it, and scrape some data after filling in the form, and it seems the easiest way is to use robobrowser.
However, I can't import robobrowser. I have installed robobrowser several different ways and robobrowser is located here:
C:\Users\(USERNAME)\AppData\Local\Programs\Python\Python37-32\Lib\site-packages
Here is my script:
import requests
from bs4 import BeautifulSoup
import datetime
import webbrowser
import re
from robobrowser import RoboBrowser
br = RoboBrowser()
etc....
The problem is the script will not run past "from robobrowser import RoboBrowser" and I get the following message:
ImportError: cannot import name 'RoboBrowser' from 'robobrowser'
Maybe your robobrowser package is corrupted
Now try Installing robobrowser using PyPI
first check if python package named as PyPI is installed on your system using this command in your terminal
pip --version
if it is installed then it will show the output like that
To install robobrowser using PyPI run this command in your terminal
pip install robobrowser
now import it
from robobrowser import RoboBrowser
br = RoboBrowser()

NLTK not working on iPython

I'm working with MacOS, I've installed Python and iPython, but when I type:
import nltk
ipython tells me that there is no module named nltk. However, when I type in:
import sys
import nltk
It works perfectly fine. Can someone explain why this isn't working correctly? I'm a newbie to Python so please be gentle. Thanks.

failed to import numpy as np when I worked with jupyter notebook

In Jupyter, there is an ImportError:
import numpy as np
ImportError Traceback (most recent call last)
ipython-input-1-4ee716103900 in module()
----> 1 import numpy as np
ImportError: No mudule named numpy
But in Python, there is no error:
import numpy as np
Usually this happens because your python is one Python environment and whatever you're running your notebook with is another. Try running import sys; sys.executable in both environments and seeing whether or not they match. If they don't, that's your problem: whatever jupyter is running in is borrowing numpy from the root environment.
For ubunutu environment
in jupyter, run:
import sys; sys.executable
This will display the python location eg
/home/paul/notepad_vm/notepad_vm/bin/python
switch to bash shell
cd /home/paul/notepad_vm/notepad_vm/bin/python
./pip install numpy
switch back to Jupyter, run:
import numpy as np

No module named linear_modelsklearn._model

from sklearn.linear_modelsklearn._model import SGDClassifierNo module named linear_modelsklearn._model
I am on OSX version 10.9.4
Python 2.7.6
numpy 1.9.0
scipy 0.14.0
scikit-learn 0.15.2 What I am missing? Thanks.(import sklearn works fine but not the model)
Your import seems wrong, try:
from sklearn.linear_model import SGDClassifier