Recently been having trouble using python on my laptop. I used to have windows 8.1 in my laptop, but saw most of my classmates use python with windows 10. So I updated to windows 10. Still having problems. I ended up using my desktop which has windows 7 and it worked perfectly. The problems have been when I would try and plot graphs or when id use arange. My question is, does windows really play a factor on python? they both have python version 3.5.1 python build 4 and 144 installed packages.
from numpy import *
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import *
from pylab import *
import pylab as pl
from matplotlib.pyplot import *
from math import exp, expm1
from __future__ import division
%matplotlib inline
There is nothing to do with windows. Either way you can uninstall python and reinstall it,may resolve your problem. But make sure you have installed numpy as well.You can get package for that http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy . Python installation has nothing to do with your windows version.
Related
I have installed matplotlib on ubuntu windows subsystem and run this simple code:
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
plt.plot([1, 2, 3, 4])
plt.show()
But it just does not show up anything.
So I tryied to install matplotlib on windows powershell and then executed the same code and it worked well:
Well even know it worked fine using powershell I really want to run my programs using linux susbystem, what should I do?
WSL does not support graphics.
You need to setup X server for WSL.
Have a look at https://x410.dev/
With the r package reticulate, I attempted to import the python package scipy to do my data analysis. However, it says
ModuleNotFoundError: No module named 'scipy'.
But when I use jupyter notebook, clearly I can import scipy so my computer has the package. Somehow RStudio is not importing it.
This is what I did:
library(reticulate) #import reticulate to enable python usage in r
use_python("/usr/local/bin/python3", required = TRUE) #set the path for where my python is.
from scipy.optimize import minimize #try to import the package in a python block
Then I get the error package not found. I tried so many things this afternoon but failed
First, I tried to install again using r studio with py_install("scipy"). It installs, but when I try to import again, it still reports not module found.
Second, I tried to create virtual environments by conda_create('r-reticulate', packages = "python=3") and then py_install("scipy"). Doesn't help.
Third, I upgraded the python to python 3.7. Now not only the scipy package, but all python packages like numpy, pandas also could not be imported. Of course they can still be imported in Jupiter notebook so it's not the case that my computer does not have them.
I tried the previous two things again but no help.
library(reticulate)
use_python("/usr/local/bin/python3.7", required = TRUE)
from scipy.optimize import minimize
import matplotlib.pyplot as plt # for plotting
import numpy as np # for numeric calculations
import pandas as pd # for python data frame
import time
I expect to successfully import all the python packages to RStudio. And figure out a way to install new python packages and import them to r.
I'm using Windows 10, anaconda navigator, and jupyter notebook 5.7.4 throws an error when I try to import 'basemap' using "from mpl_toolkits.basemap import basemap"
I'm very new to python. Following a tutorial to learn GIS mapping with python, I've installed all the required packages: pandas, numpy, geopandas, basemap, matplotlib, pillow and a few others.
The tutorial code says to write "from mpl_toolkits.basemap import basemap"
However, mpl_toolkits does not appear to be an available package when I search for it in the anaconda navigator or in the anaconda prompt.
Having searched the anaconda user guide and the matplotlib web page, I am inferring that mpl_toolkits is included within matploblib?
The error that results is this: ImportError: cannot import name 'basemap' from 'mpl_toolkits.basemap' (C:\Users\Kevin\AppData\Local\conda\conda\envs\mapping\lib\site-packages\mpl_toolkits\basemap__init__.py)
# command to display matplotlib plots inline within the ipython notebook
%matplotlib inline
# import necessary modules
import numpy as np, matplotlib.pyplot as plt, pandas as pd, geopandas as
gpd
from mpl_toolkits.basemap import basemap
from shapely.geometry import Point
from geopy.distance import great_circle
I expect the jupyter notebook to load all of the modules but instead I get the above error.
Any help is much appreciated, this is my first go at something like this so I am probably making a simple neophyte mistake.
Seems this is very peculiar to Anaconda. If you correctly installed all the dependencies you should check this Python basemap module impossible to import
I am trying to set up a python3 development environment on my Pixelbook.
I enabled native linux app support on it by switching to developer branch, so now I have a working bash shell with apt.
I was able to install gvim and python3.5.3 and pip. I installed numpy, scipy, pandas and matplotlib fine. All the other packages work smoothly, and I can import matplotlib, but as soon as I try to call any method from matplotlib it hangs my shell and never returns.
Here is a simple scripts I use for testing:
import scipy as sp
import matplotlib.pylab as plt
t = sp.arange(0, 10, 1/100)
plt.plot(t, sp.sin(1.7 * 2 * sp.pi * t) + sp.sin(1.9 * 2 * sp.pi * t))
plt.show()
I try to run it like this, but it never returns and Ctrl+C doesn't help either:
Command output
I tried using a different backend like this:
import matplotlib
matplotlib.use("TkAgg")
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
It doesn't help either.
Some people suggest using matplotlib.ion(), but it didn't change anything either.
I found this thread where someone was also having a hard time using matplotlib on a pixelbook.
The solution proposed there was to install spyder, so I did, like this:
sudo pip3 install -U spyder
This didn't help either.
It seems to me that matplotlib cannot find the graphics back end on my machine. I am running crouton and as I mentioned before gvim installed just fine. This is after the google announcement of support of linux native apps on chromebooks, so I am not running in a VM, this is stock chrome os moved to dev branch and switched to enable linux.
I am wondering if I need additional X11 backend installed separately, but I checked google documentation for installing Android Studio on Pixelbook, and it didn't mention any additional graphics installations, just "enable linux and install the linux tgz package". I would really appreciate some pointers.
When I run 'pip freeze' it shows that numpy==1.8.1; however, when I start Python and import numpy and then check the version number via numpy.version.version I get 1.6.
This is confusing to me and it's also creating a problem for scipy and matplotlib. For example, when I attempt to do the following import 'from matplotlib import pyplot' I get an error saying 'RuntimeError: module compiled against API version 9 but this version of numpy is 6'. This I'm guessing has something to do with the numpy versions being wrong.
Any suggestions?
From our conversation in chat and adding path to .bashrc not working:
Putting:
/usr/local/bin first in /etc/paths will resolve the issue