Python modules not working in IDLE - macos

Working on Automate The Boring Stuff project and having trouble with pyperclip and IDLE. pyperclip is successfully downloaded and works fine in Terminal but when I import pyperclip in IDLE, I get the below error.
UPDATE - This is happening with other modules - anything I've installed in the terminal aren't importing into IDLE.
import pyperclip
Traceback (most recent call last):
File "", line 1, in
import pyperclip
ModuleNotFoundError: No module named 'pyperclip'
I figure I have the module saved in the wrong folder somehow. Below are the sys.path outputs from my Terminal and IDLE.
In terminal:
'/anaconda/bin',
'//anaconda/lib/python36.zip',
'//anaconda/lib/python3.6',
'//anaconda/lib/python3.6/lib-dynload',
'//anaconda/lib/python3.6/site-packages',
'//anaconda/lib/python3.6/site-packages/Sphinx-1.5.1-py3.6.egg',
'//anaconda/lib/python3.6/site-packages/aeosa',
'//anaconda/lib/python3.6/site-packages/IPython/extensions',
'/Users/andrewricardo/.ipython']
In IDLE:
sys.path
['', '/Users/andrewricardo/Documents', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages']
There are multiple paths here - how do I effectively move the pyperclip module to the correct place?
OR - Is there something else going on here?

Each python installation and uses its own .../lib/site-packages for 3rd party modules, and you have two. If you ran the non-anaconda python in the terminal, the same that is running IDLE, it would have the same problem. Indeed, that python is the source of the ImportErrors.
Option 1: Separately install all packages you want to use with the non-anaconda python (and IDLE) in its own site-package directory. In IDLE Shell, get the path to its executable
>>> import sys; sys.executable
Save are remember the resulting 'python-path'. Then in the terminal, run
python-path -m pip install package-name
for each package.
Option 2 (uses a little known feature of site-package directories): in
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
add a file name, for instance, anaconda.pth, containing one line.
//anaconda/lib/python3.6/site-packages
(I have no idea why the double / or if it is really needed; I just copied it from your question.) This makes the anaconda python site-packages an extension of the framework python site-packages. Since both are for 3.6, one copy should work for both.

Had this same issue and googled
'why is importing pyperclip in my python file giving an "modulenotfounderror"but working fine in the idle'
and this page came up. then i also checked this [installed Pyperclip, trouble importing to IDLE.
I am new to python, had the same issue using the same book after pip installing pyperclip here's what I did to solve this issue.
I copied the pyperclip-1.7.0-py3.7.egg-info and pyperclip folders from
C:\Users\USER\AppData\Local\Programs\Python\Python37\Lib\site-packages into the C:\Users\USER\Anaconda3\Lib\site-packages folders and C:\Users\USER\AppData\Local\Programs\Python\Python37 folders and it worked. Hope this helps. If it doesn't. Try this code in your text editor because that's what I did using Atom and how i was able to solve it.
import sys
print(sys.executable)
Then copy the pyperclip-1.7.0-py3.7.egg-info and pyperclip folders into the path that the above code gives you.

Related

Python3.7: No module named

I've been trying to install matplotlib and textblob on my system using
pip3 install matplotlib
or
pip3 install textblob
It says it's installed successfully. However, when I try to import in in Sublime Text it says
ModuleNotFoundError: No module named 'matplotlib'
or
ModuleNotFoundError: No module named 'textblob'
I've set up the build system in sublime text for python 3. A lot of modules that I've installed and are using the same way works fine (BeautifulSoup, requests and tweepy for example). I do not understand why some modules work and others do not. I've been trying to find the solution to this problem but after hours of research without results, I see this question as my last resort. Very thankful for all help.
shell_cmd: /usr/bin/env python3

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

Clean install of Scientific Python without reformatting the disk

1st, the Disclaimer: I looked at numerous questions here, there is question about uninstalling all pip–installed, uninstalling matplotlib, moving to 3.5 from 2.7, –– but I didn't find an answer to my specific problem. Sorry if I didn't look hard enough.
Basically, my problem is I have a mess of different packages installed by different means at different times. Manifestations of this are:
1) I can import numpy from python but not from Jupyter notebook:
------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-5a0bd626bb1d> in <module>()
----> 1 import numpy
ImportError: No module named numpy
2) I cannot import nltk:
...
File "numpy.pxd", line 155, in init sklearn.utils.murmurhash (sklearn/utils/murmurhash.c:5029)
ValueError: numpy.dtype has the wrong size, try recompiling
likely many more.
I recently uninstalled jupyter and anaconda, installed anaconda again, - this didn't help.
I cannot uninstall numpy / scipy , although I can use them (?!?):
>:~%python -c 'from numpy.random import rand; print rand()'
0.946167984715
>:~%pip uninstall numpy
Cannot uninstall requirement numpy, not installed
I have two versions of Python:
2.7.11 under /usr/local/bin/ pointing to /usr/local/Cellar/python/2.7.11/bin/python
2.7.10 under /usr/bin/ pointing to
/System/Library/Frameworks/Python.framework/Versions
-- although the default is 2.7.10 (numpy works with it), and I think 2.7.11 was added by Anaconda (incorrectly, because it doesn't see numpy).
Yesterday I uninstalled everything I could think of, then upgraded to a new version of Mac OS (10.12.2 Sierra), and then re-installed anaconda – in vain.
I am close to reformatting the disk and starting from scratch.
Is there a better option?
Thank you! and sorry for so many details.
Not sure exactly on a MAC but these are the things to try on windows and it is probably similar on MAC.
Start with a clean install of anaconda then try "where python" and "where jupyter" (it is "which" instead of "where" on linux). This tells you where it is looking for the executables. Both should be subfolders of anaconda. If they are not check your PATH variable.
Now start python or jupyter; import sys and try sys.path. That tells you where python is looking for stuff. It should look only in anaconda sub folders.

Installing pygame on Windows (custom Python location not supported?)

I am running Python 3.5 on Windows 8. I am trying to install pygame. I downloaded and ran
pygame-1.9.2a0.win32-py3.2.msi (6.4 Mb)
from
http://www.pygame.org/download.shtml
From python I get, after starting a new session:
>>> import pygame
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
import pygame
ImportError: No module named 'pygame'
How do I install? Was my PythonPath updated? Looking at sys.path, it doesn't look like it. How do I get Python to see the library? Where was the library installed? Thanks for the help.
Update1:
The first step i the pygame intsaller states "Select Python Installations - Select the locations where pygame-1.9.2a0 should be installed." Underneath that is a selection that states "Python from another location". This doesn't make sense to me. Anyone?
Update2: I solved the problem - I reinstalled python in the default location (it wasn't before). The pygame installer doesn't seem to support custom installations. Ok, fixed. Thanks all for the help.
Up to now, Windows binaries must match the Python binaries. ...py-3.2.msi is for 3.2 and will not work with 3.5. Either get a 3.5 binary from the site you already used or use pip to install pygame-1.9.2a0-cp35-none-win32.whl from http://www.lfd.uci.edu/~gohlke/pythonlibs/ Use pip install /? to get info on how to install from somewhere other than pypi. It might be easier to download the file to your machine first. The site above says a bit about this.
Make sure you have 32-bit python and pygame.

kmpfit module not in Kapteyn v2.2 module list

I am using Python 2.7 through Anaconda 2.7.8 and need Kapteyn 2.2 to perform Non-linear Least Squares fitting easily (it is probably an alternative to Scipy.optimize.leastsq() for dummies like me!).
After copy-pasting this from a previous post here on Stack Overflow:
conda install -c https://conda.binstar.org/dhirschfeld pyodbc
and then running on my cmd (as I did not have pyodbc installed I think, because of which maybe the command prompt on my Windows 7 64-bit system was not responding well to python setup.py install inside the Anaconda directory where I unzipped the Kapteyn .zip file downloaded from University of Groningen website.
But, after the installing pyodbc properly and running python setup.py install, the cmd gave me an error saying error: command 'C:\Users\windows 7\Anaconda\Scripts\gcc.bat' failed with exit status 1. Later, when I tried to import kmpfit module (needed for Non-linear least square fitting with Kapteyn), here is the problem:
import kapteyn
help(kapteyn)
Help on package kapteyn:
NAME
kapteyn - Kapteyn package.
FILE
c:\users\windows 7\anaconda\kapteyn\__init__.py
PACKAGE CONTENTS
_ni_support
celestial
doccer
filters
interpolation
maputils
mplutil
positions
rulers
shapes
tabarray
wcsgrat
DATA
__all__ = ['celestial', 'wcs', 'wcsgrat', 'tabarray', 'maputils', 'mpl...
__version__ = '2.2'
VERSION
2.2
As you can see, there is no module named kmpfit (or even wcs) here. But according to http://www.astro.rug.nl/software/kapteyn/intro.html, these two should be there.
Kindly help. I have never imported any module before.
Thanks in advance...:-)
I just managed to get this working (on Mac OSX, so you may have to adjust this). My steps were:
$ conda install pyodbc (didn't need to go through binstar)
Download & unarchive the kapteyn package, then navigate to its directory
$ python setup.py install, which used my OS's C compiler and Anaconda's python, and installed kapteyn to my anaconda distro's site-packages, as it should.
Check that kmpfit.so is in the kapteyn folder in site-packages, showing that kmpfit installed correctly.
>> from kapteyn import kmpfit failed, ImportError: cannot import name kmpfit. I did some digging and discovered that it was still importing kapteyn from the folder that I downloaded, not from site-packages.
Delete the downloaded kapteyn folder, then try again. It worked!

Resources