Unable to import PyroModule - python

I am trying to import PyroModule using: from pyro.nn import PyroModule but, I am getting this error:
ImportError: cannot import name 'PyroModule' from 'pyro.nn' (/home/karima/anaconda3/envs/my_env/lib/python3.7/site-packages/pyro/nn/init.py)
Here is the whole piece of code:
import os
from functools import partial
import torch
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import pyro
import pyro.distributions as dist
from torch import nn
import seaborn as sns
from pyro.nn import PyroModule

I think the issue is due to wrong installation of pyro module,
instead of this
pip install pyronn
can you try this
pip install pyro-ppl
Let me know how this goes

I was facing the same problem with my MAC. None of the suggestions worked for me. I resolved it by running python -m pip install pyro-ppl
I hope this helps.

Related

Python in vscode: Import errors do not show up in terminal

I'm writing python scripts in vscode and recently I've been having a problem related to imports.
Lines of code above imports work and their output is displayed in the terminal:
print("hellow")
import matplotlib.pyplot as plt
import numpy as np
#from scipy.special import erfc
from scipy.linalg import solve
> hellow
Lines of code below the imports are not executed, but no errors are displayed in the terminal!
import matplotlib.pyplot as plt
import numpy as np
#from scipy.special import erfc
from scipy.linalg import solve
print("hellow")
>
I'm guessing there is something wrong with my vscode settings, but why are no errors showing up in the terminal?
Thanks for your help.

Anaconda: ImportError: Cannot import name '_imaging' from 'PIL' (matplotlib.pyplot)

I'm trying to plot the histogram using matplotlib.pyplot library.
from matplotlib import pyplot as plt
plt.hist(df["xxx"])
When I'm trying to import that library I'm getting the error:
ImportError: cannot import name 'imaging' from 'PIL'(C:\Users\Taras\AppData\Roaming\Python\Python38\site-packages\PIL_init.py)
I'm using Anaconda and Jupyter Notebook.
Try this code as you have made it very complicated
import matplotlib.pyplot as plt
%matplotlib inline
plt.hist(df["xxx"])
You need to change the first line of your code to the following:
import matplotlib.pyplot as plt
The second line of code is okay, but I don't understand what the third line of code is doing. What dataframe are you trying to print? I copied and pasted a dataframe from the web and then ran your code changing the first and third lines of code.
All runs good in Jupyter Lab using the python kernel.
import matplotlib.pyplot as plt
from matplotlib import pyplot
df = pd.DataFrame({
'name':['john','mary','peter','jeff','bill','lisa','jose'],
'age':[23,78,22,19,45,33,20],
'gender':['M','F','M','M','M','F','M'],
'state':['california','dc','california','dc','california','texas','texas'],
'num_children':[2,0,0,3,2,1,4],
'num_pets':[5,1,0,5,2,2,3]
})
df.plot(kind='hist',x='num_children',y='num_pets',color='red')
plt.show()
The plot can be viewed at the link below.
link
you can solve this problem by import Image lib manually
import PIL
from PIL import Image
import matplotlib.pyplot as plt
Unistalling and reinstalling pillow should work.
pip uninstall Pillow
pip install Pillow

Spyder (Python 3.6) wkhtmltopdf ModuleNotFoundError: No module named 'main'

I'm a relatively inexperienced programmer and I ran these import statements last week on my computer without a problem but now this week when I run the following statements in particular the wkhtmltopdf import I run into an error.
import pyodbc
import pymysql
import numpy as np
import pandas as pd
import datetime
import jinja2
import wkhtmltopdf
from wkhtmltopdf.main import WKhtmlToPdf
import datetime
import calendar
from pathlib import Path
This leads to this error
enter image description here
Any help is appreciated

How to fix mpl_finance package for MatPlotLib?

Getting this error message:
MatplotlibDeprecationWarning: The finance module has been deprecated in mpl 2.0 and will be removed in mpl 2.2. Please use the module mpl_finance instead.
How do I put in place the mpl_finance package instead. I have it installed in pip, but what is the proper import phraseology?
import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
from matplotlib.finance import candlestick_ohlc
import matplotlib.dates as mdates
import pandas as pd
import pandas_datareader.data as web
from googlefinance import getQuotes
import json
from datetime import datetime
from forex_python.converter import CurrencyRates
from yahoo_finance import Share
All code for matplotlib.finance moved to a separate repository. Here is an example of usage. To answer your question:
from mpl_finance import candlestick_ohlc
To import a module which is installed through pip with the name x you would mostly want to do import x.
So, here
import mpl_finance
or to get one of its functions, e.g.
from mpl_finance import candlestick_ohlc
new version can be found here: https://pypi.org/project/mplfinance/

How to get matplotlib working in Python3 on OS X?

I am trying to do Google's deep learning course on Udemy. For assignment one I need to verify that the following modules are working on my machine, but can't get matplotlib.pyplot working. The python code I must get to compile is the following:
# These are all the modules we'll be using later. Make sure you can import them
# before proceeding further.
from __future__ import print_function
import matplotlib.pyplot as plt
import numpy as np
import os
import sys
import tarfile
from IPython.display import display, Image
from scipy import ndimage
from sklearn.linear_model import LogisticRegression
from six.moves.urllib.request import urlretrieve
from six.moves import cPickle as pickle
# Config the matplotlib backend as plotting inline in IPython
%matplotlib inline
When I compile and run this like so:
python3.6 nn_assignment_1.py
I get the following error:
Traceback (most recent call last):
File "nn_assignment_1.py", line 9, in <module>
from IPython import display, Image
ImportError: cannot import name 'Image'
Any ideas how to get matplotlib working for python 3 here? I have been banging my head against the keyboard for hours trying to figure this out.

Categories

Resources