Python ImportError no module named statistics after downloading - linux

I'm trying to run my code and I don't know what specific package I need in order to get my import statement to work. Below is my header and I keep getting an error saying ImportError no module named statistics. I have looked at a bunch of different pages to see where I can download a solution, but I am trapped. I know my code works because I ran it on my schools lab. If anyone can help, that' be great!
Just note I am a beginner and am using Linux on my virtual machine with Python 2.7
import sys
import requests
import matplotlib.pyplot as plt
import statistics as stat

Statistics "A Python 2.* port of 3.4 Statistics Module" (PyPI).
If you use 2.7.9, you will have pip installed, and pip install statistics within the 2.7 directory should install the module for 2.7 (I am not a pip or virtual machine expert, so might be slightly off.)

It comes pre-installed in python --Version 3. To import in python version 2 in Ubuntu, open Terminal and type
sudo pip install statistics
Enter your password and it will get installed.
Ps: you need to have pip already installed.

You need to be using python 3.4 to import statistics. Upgrade to the current version and you should have no problems.

Related

XGBoost module not found in site-packages. Imports but doesn't work. (mac OS)

I was able to install xgboost on my mac and have it so that I can import the module without any errors. However I cannot use it. When I try to import XGBRegressor. I get the following error :
cannot import name 'XGBRegressor' from 'xgboost' (unknown location).
Some of the support for this type of problem says that there may be more than one xgboost location, and that python is selecting the incorrect xgboost, however I have not been able to find how to fix this problem.
When I print the xgboost.__file__ location, it returns 'None'. However I know its in the site-packages folder in my python path.
I have python 3.9
Maybe this.
conda install -c conda-forge xgboost=0.6a2
Then, restart Spyder and re-run!

Pandas install or import in IBM SPSS Statistics Version 26

I have installed the latest version of IBM SPSS Statistics(Version 26) which has pre installed python 3.4 and 2.7. i am trying to use version 3.4 python. i am able to import modules like pip , sys , os etc. i tried pandas the same way. i am unable to do so. getting error no module found. Hence going through our forum and IBM support did the following changes.
received the following error
1) tried pointing the site-packages via
import sys
# Assuming windows and standard python folder here.
sys.path.append(r"D:\Python34\Lib\site-packages")
2) changed the path in the settings of SPSS
3) Tried installing pip in the below folder as suggested in the forum but got message i have already installed the updated version.
C:\Program Files\IBM\SPSS\Statistics\Subscription\Python3
4) following versions of python were installed
have tried what i could. Need your expertise help to fix the same which will help me to install/use modules needed for SPSS. Thanks.
This is going to be painful to explain, I'll do my best.
As far as I can tell, you're on windows. Usually when we need a new package, we just open cmd and type pip install xxx (assume you added python to path when installing it). The reason that this works, is because when you type pip install xxx in cmd, windows recognize pip to be a command because python path is in system variables. Windows know that I can execute pip install with this python path.
However for SPSS python (3.4), that python had a different path in the system. Thus when you only have the 3.7 or 3.8 python in path, windows cannot install package to you 3.4 python, and I'm not sure if you can have more than one python path in system.
In order to fix this, you need to first figure out what's the path to your 3.4 python, then in this page you can follow the instruction to remove your 3.7 or 3.8 python in path, and add your 3.4 path, then you can do pip install xxxx for whatever package you want
I did the same thing with a arcgis python distribution, hope this works for you. If the attached page does not work, just google add python path to windows and look for a instruction that works on you PC
Oh and the reason that you can import pip, sys and some other package but not pandas, is because python is 'battery included', it comes with tons of packages pre-installed for additional functionality, but pandas is not one of them.
Fixed it since my ananconda had version 3.7 .i created virtual environment and installed 2.7 python with anaconda package. Pointed SPSS to the 2.7 folder and was able to import pandas.

how to fix install of requests library?

I am learning Python, using Windows and Vs Code editor.
My .py simply contains : import requests
and I see this error ModuleNotFoundError: No module named 'requests'
I think the library is installed because :
Pip freeze shows : requests==2.22.0
pip install requests shows : Requirement already satisfied: requests in d:\python\lib\site-packages (2.22.0)
What am I missing?
Thanks,Peter
It's likely you're using a python version that it's in a different location, do you have multiple versions of Python installed?
One easy way to see what packages you're using on that version of python is to do
>>> import site
>>> site.getsitepackages()
It's generally a good idea to use virtual environments for Python to help with that kind of package control

Unable to import sklearn and statsmodels from Anaconda from windows 10 pro

I'm relatively new to python, so please excuse my ignorance on what could be a very easy fix. I am running python 3.6 through the Rodeo IDE, and it has been great, as it is similar to R-Studio (which I am very familiar with). As an aspiring data scientist, I am trying to learn how to fit regression and time series models to data, and all of the tutorials that I have found all say that I need various packages, all of which should be included in the Anaconda library. After downloading and re-downloading Python, Rodeo, and Anaconda, and trying various online fixes, I have been unable to successfully load the scikit-learn and the statsmodels modules.
#here is everything I have tried.
#using pip
! pip install 'statsmodels'
! pip install 'scikit-learn'
! pip install 'sklearn'
I don't get any errors here, and to be honest I'm kind of confused as to what this actually does, but I have seen many people online always suggest that this is a big problem when trying to import modules.
#using import
import sklearn
import statsmodels
from sklearn import datasets
import statsmodels.api as sm
all of the above give me the same error:
import statsmodels.api as sm
ImportError: No module named 'statsmodels'
ImportError: Traceback (most recent call last)
ipython-input-184-6030a6549dc0 in module()
----> 1 import statsmodels.api as sm
ImportError: No module named 'statsmodels'
I have tried to set my working directory to the Anaconda 3 file that has all of the packages and rerunning the above code with no success.
I'm thinking that the most likely problem has to do with my inexperience, and it is probably a simple fix. Is it possible that the IDE is bad or anaconda just doesn't like me?
So keeping all of the above in mind, the question is, how can I import these modules successfully so that I can access their functionality?
Option 1:
After installing packages with pip, try closing and reopening your IDE/Jupyter Notebook and try again.
This is a known bug that Jake VanderPlas outlined here
Option 2:
Don't put quotations around your pip messages.
!pip install -U statsmodels
!pip install scikit-learn
Option 3:
Also are you using Anaconda? If you are, you should already have scikit-learn. If you are trying inside Rodeo, I think you need to set your path inside Rodeo. Open Rodeo and set the Python Path to your fresh anaconda. See here

Pip in python34 does not work properly (OS Windows)

I'm writing a data extraction from xls python script using xlrd. I'm having trouble however with pip, I just managed to get a positive reply from the cmd when i requested (I had some trouble with it at first, but a few posts helped out)
py -m install requests
The response I now get is: "Requirement already satisfied." (with some mention of update since my pip version is 6.0.8 and there's a 7.0.1 available)
However, when I run my code part of which can be seen below I get a syntax error.
import xlrd
from xlrd import open_workbook
import xlwt
workbook = xlrd.open_workbook('editable.xls')
The error:
File "C:\Python34\lib\site-packages\xlrd__init__.py", line 1187
print "EXTERNSHEET(b7-):"
^ SyntaxError: invalid syntax
I run your program on Ubuntu/Linux and it runs fine.
I will recommend to follow my instructions for installing the xlrd on your Windows machine.
From here download the latest version of the xlrd.
Then extract the file, and using the command prompt in the new xlrd directory type:
python3 setup.py install
Unfortunately I don't own a Windows machine so I can't guaranteed to you that this is the right way to install it.
The trick was that you should run the setup.py using the python3 and not the python
(note that on my machine, I run the above command using sudo, which means in Linux administration permissions, so if you have any problems try to run your command prompt with administration permissions.)
I test this code on my Ubuntu machine:
import xlrd
from xlrd import open_workbook
workbook = xlrd.open_workbook('Untitled.xls')
I remove the import xlwt as I don't have this module, please try and let me know.
Edit: Also you will need the setuptools installed on your computer.

Resources