Python3 cannot find statsmodels.api but I can and so can my linter - pip

I recently got into development with Python running on WSL (Ubuntu 18.04 LTS).
I followed the documentation from here and I'm able to run simple python scripts.
I started playing around with libraries that I installed using the pip3 command such as numpy and pandas and these work fine.
The problem arises when I try to use the statsmodels package.
I've installed it using pip3 install statsmodels
I can see the package in /home/username/.local/lib/python3.6/site-packages/statsmodels I can even see the api.py file in that directory, however, when I type import statsmodels.api as sm as recommended on the statsmodels website I get:
Console output:
username#DESKTOP-1JP4BIE:/mnt/c/users/username/dev/project/playground$ python3 statsmodels.py
Traceback (most recent call last):
File "statsmodels.py", line 5, in <module>
import statsmodels.api as sm
File "/mnt/c/username/chris/dev/project/playground/statsmodels.py", line 5, in <module>
import statsmodels.api as sm
ModuleNotFoundError: No module named 'statsmodels.api'; 'statsmodels' is not a package
I've tried uninstalling and reinstalling (did not work)
I really can't see anything that differentiates this package from the others that I've installed. Does anyone have any insights?

Thanks #Vorsprung durch Technik
The issue was that my file name was statsmodels.py.
I'll remember to be more careful when naming my python files.

Related

Visual Studio Code ModuleNotFoundError: No Module Named Seaborn

can you help me out with this
I'm trying to import seaborn as sns
but on my screen, it just showed
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'seaborn'
I tried to uninstall then re-installed seaborn on anaconda so many times but it doesn't work
Thank you for your help
Please, check if, in VSCode, you are using the Python environment in which you installed Seaborn. Refer to this post. You may be using a Python environment that is not from Anaconda.
You may also try to install the package via VSCode, using the normal conda or pip commands as they tell here. In this case, the package is installed in the environment in use.

Python 3.9 import issue

I just installed Python 3.9 with the Windows 64-bit installer. For some reason the all of the modules I had previously installed using pip will no longer import, unless I am running Python from the directory where they are located: C:\Users\<user>\AppData\Local\Programs\Python\Python38-32\Lib\site-packages
I tried uninstalling/reinstalling the requests module with pip and then importing requests in a shell, still not recognized.
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'requests'
I imagine this is probably some environmental variable path issue. I'm new to Python, any help getting this straightened out much appreciated.
Each version of python has its own global sites package directory where it stores the packages you install.
Ex: Python 3.8 will store under %appdata%\Local\Programs\Python\Python38-32\Lib\site-packages
Python 3.9 would store it in a different location (like Python39-32)
In order to install a package for specific version of python you need to install it with python version command.
py -3.9 -m pip install requests
You can refer the official documentation here

Unable to run Autokey Ubuntu 18.04

I am relatively new to Linux/Ubuntu (so please take it easy on me) and I am trying to install Autokey to use the text expansion functionality. I have tried installing it from the instructions on the Github page here - https://github.com/autokey/autokey#installation
However, no matter whether I follow the installation process under the Ubuntu/Mint/Debian section or the instructions to install via pip I cannot seem to get the program working.
The installation seems to be successful (running a 'which' command gives the path installed) but clicking on the icon does not launch the program.
I have also tried to install directly from Ubuntu/GNOME software manager but that also will not launch the program once installed.
I have tried installing both the GTK and QT frontends and neither will launch. I don't get an error message or anything. I have opened up the System Monitor to see if a process even appears (however briefly) and there's nothing.
Typing autokey-gtk into Terminal gives:
/usr/local/lib/python2.7/dist-packages/autokey/gtkapp.py:24: PyGIWarning: Gtk was imported without specifying a version first. Use gi.require_version('Gtk', '3.0') before import to ensure that the right version gets loaded.
from gi.repository import Gtk, Gdk, GObject, GLib
Traceback (most recent call last):
File "/usr/local/bin/autokey-gtk", line 20, in <module>
from autokey.gtkapp import Application
File "/usr/local/lib/python2.7/dist-packages/autokey/gtkapp.py", line 28, in <module>
import service, monitor
File "/usr/local/lib/python2.7/dist-packages/autokey/service.py", line 21, in <module>
from iomediator import Key, IoMediator
File "/usr/local/lib/python2.7/dist-packages/autokey/iomediator.py", line 107, in <module>
from interface import *
File "/usr/local/lib/python2.7/dist-packages/autokey/interface.py", line 29, in <module>
from Xlib import X, XK, display, error
ImportError: No module named Xlib
Can anyone please help? Thank you.
I am a newbie too and installed Autokey 0.90.4, which did not work for me either. Someone suggested I try 0.95.1 because the other version is 7 years old.
I installed the new version with some acrobatics from the Autokey Github page, using the PIP method. At 1st it did not work, but after doing import setuptools it did. That might be a coincidence since it was after installation of the Ak package itself.
I know this sounds convoluted, but I am not familiar (yet?) with Linux. Anyway 0.95 works for me.
install module python-xlib and it will work, like this:
On Deb:
apt install python3-xlib
You might later need python autokey module as well:
pip install autokey

ImportError: No module named googlemaps

I've installed this package via pip27 on macports. My OS is OSX El Capitan 10.11.6. My python install is 2.7.10.
I'm trying to run an example script that imports googlemaps module, but I keep getting that ImportError. I have a feeling that it's how pip installed it and the reason why python can't find it, but I'm relatively new to pip so I don't know where to start investigating.
I also tried googling for a fix but no dice. Any idea what's happening here?
Here's my code:
import googlemaps # can't import
import argparse
from datetime import datetime
# collect args for lat, long, # of addresses, radius of search
parser = argparse.ArgumentParser(description='Randomize addresses on Google Maps')
parser.add_argument('-lt', '--latitude')
parser.add_argument('-lng', '--longitude')
parser.add_argument('-n', '--count')
parser.add_argument('-r', '--radius')
args = parser.parse_args()
print('Results: ', vars(args))
Error message:
Traceback (most recent call last):
File "randomize_addresses.py", line 1, in <module>
import googlemaps
ImportError: No module named googlemaps
Found a fix. I uninstalled googlemaps via pip and then reinstalled using easy_install. Apparently OSX doesn't like pip.
Looks like you used pre-installed python since you mentioned version 2.7.10 (default version shipped with macOS) which is located at /usr/bin/.
MacPorts installs binaries and libraries under /opt/local. Try to install python via MacPorts and run the program again. Python and pip should both be linked so that packages installed via pip is available to python.
In this case packages installed using pip27 would be available to python27 installed via MacPorts and not /usr/bin/python.
Another way would be to download get-pip.py and install it against /usr/bin/python (pip installation guide).
Note: Make sure you are using python installed via MacPorts. To check this run which python, it should show something like /opt/local/bin/python2.7

Scipy installation windows 10

I have some difficulties trying to install Scipy for Python 3.5 on a Windows 10 machine and I hope I can find some help here. So here is what I have done so far.
I have downloaded the numpy+mkl for python 3.5 and 64bit version as well as the scipy0.18.1 for the same versions, from Gohlke's website
I installed the numpy+mkl whl with:
python -m pip install numpy-1.11.2+mkl-cp35-cp35m-win_amd64.whl
all goes well.
then I install the scipy package the same way like:
python -m pip install scipy-0.18.1-cp35-cp35m-win_amd64.whl
This also completes.
However, when I try to run python afterwards I get the following error:
Fatal Python error: Py_Initialize: can't initialize sys standard streams
Traceback (most recent call last):
File "C:\Python35\Lib\site-packages\scipy\io\__init__.py" , line 97, in <module>
File "C:\Python35\Lib\site-packages\scipy\io\matlab\__init__.py", line 13 in <module>
File "C:\Python35\Lib\site-packages\scipy\io\matlab\mio.py", line 8 in <module>
ImportError: No module named 'numpy'
I also get a pop-up that Python has stopped working.
I have tried a different order in which I installed the packages, but all lead to the error mentioned when Scipy is installed.
I also installed did this on a windows 7 machine and there it works.
Does anybody have any idea what causes this issue?
I also had some issues. So I just installed Anaconda3 insted of python directly.

Resources