Library is not in Pycharm, even though i have already installed it - python

So i wanted to use the Quandl package to learn some data processing. I installed Quandl in the pycharm package, and it worked out pretty well.
import Quandl, math
and then, i use the Quandl to get some data from the internet
data = Quandl.get('some form of data')
But then when i tried to run the python script
bash-3.2$ python Regression.py
Traceback (most recent call last):
File "Regression.py", line 2, in <module>
import Quandl, math
ImportError: No module named Quandl
In my Pycharm interpreter, i have 4 different types:
-2.7.11 (/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/bin/python2.7) I installed Quandl here
-3.5.1 (/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/bin/python3.5) I also installed it here
-2.6.9 (/System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6) It has an error to install packaging tools
-/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 Permission denied for installing
When i tried to import Quandl in the terminal through python shell, i also retired an error
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Quandl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named Quandl
I also tried the same thing for Simple CV, it also says that it's not in the module, even though I've already installed it both in 3.5 and 2.7.
from SimpleCV import Camera
cam = Camera()
while True:
img = cam.getImage()
img = img.binarize()
img.drawText("Hello World")
img.show()
bash-3.2$ python simplecv.py
Traceback (most recent call last):
File "simplecv.py", line 1, in <module>
from SimpleCV import Camera
ImportError: No module named SimpleCV
For installing 'pip', i also had an error installing it in the Pycharm terminal. I've already asked a question about it Installing pip in Pycharm 2016.3

Try to install it using pip2.7. I suspect that you are trying to execute the script with python3 (python command), however, your python interpreter in pyCharm is python2.7.
If you keep getting errors I suggest you to research a bit about virtualenvs, as it can help you had your several dependencies and interpreters easly organized by proyect. (PyCharm has support for virtualenvs)

When you invoke "python" in your console it launches the default Python interpreter (in your case Python 2.7.10). Looks like in PyCharm you selected different interpreter and installed packages on it. Make sure you use the same interpreter in PyCharm (Settings | Project | Project interpreter)

Related

'import pyPDF2' results in 'ModuleNotFoundError'

Summary of problem:
Using the python interpreter, I type import pyPDF2 and get a ModuleNotFound error even though I have installed the pyPDF2 module:
>>> import pyPDF2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pyPDF2'
What I have tried:
I am using Windows 10. I am new to python. I have installed Python 3.8.3 to a C:\Python38 folder. I have installed pyPDF2 via 'pip install pyPDF2'. The windows path includes the folders: C:\Python38\Scripts\;C:\Python38\.
At the windows Command Prompt I type 'python' and get:
c:\>python
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
At the python interpreter prompt I type 'import pyPDF2' and get:
>>> import pyPDF2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pyPDF2'
>>>
Note: There is installed an old version of python 2.7 from an ArcGIS install. Could that be causing a conflict? If not, I would rather not uninstall that version since it goes with ArcGIS, which I use.
What I am really trying to do is to automate the concatenation of 7,696 pdf files into 104 pdf files. So far my program looks like this:
import os
from pyPDF2 import PdfFileMerger
source_dir = os.getcwd()
merger = PdfFileMerger()
for item in os.listdir(source_dir):
if item.beginswith('District001_Pg'):
merger.append(item)
merger.write('District001.pdf')
merger.close()
Any help anyone is able to provide will be greatly appreciated!
If you want to run 2 different versions of python in the same machine without having conflicts, you can use VirtualEnv. Here is a document which I found on the web to get you started.
https://www.freecodecamp.org/news/installing-multiple-python-versions-on-windows-using-virtualenv/

Can't import pyttsx in Python 2.7 on Ubuntu Linux 16

I'm trying to use pyttsx on Ubuntu Linux (64 bit, PC) with Python 2.7. I've successfully used pip to install the package
$sudo -H pip install pyttsx
$pip list
...
pyttsx (1.1)
...
When I try to import it the import call fails
$ python
Python 2.7.12 (default, Nov 20 2017, 18:23:56)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyttsx
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pyttsx
I'm not sure why I'm getting this. When I search for the question here on Stack Overflow I encounter one other instance about the same error message on a Raspberry Pi. But the solution mentioned there doesn't bring resolution on my PC so I don't think it is not related.
Any ideal what I am missing that is preventing the import from being successful?
Make sure your pip is tied to your python installation by checking both path's.
In Pip check:
`pip --version`
pip 9.0.1 from C:\Python27\lib\site-packages (python 2.7)
Later in python:
import sys
print sys.executable
C:\Python27\python.exe
run which pip, which python, make sure they are same suite
when run pip install, it should feedback the package is installed in which path
run this code in python
import sys
for i in sys.path:
print i
to check if your syspath including that path or not.

PIL, Pillow, Image, cv2 modules not found

I'm running on a mac and having an issue with trying to get Pillow working.
My versions are:
python - 2.7.6
pip - 9.0.1
Pillow - 4.0.0
I ran:
pip install Pillow
pip install PIL
pip install numpy
I have uninstalled all and re-tried; but nothing seems to be working.
I use:
from PIL import Image
or
import Image
both of which do not work. When I run "pip show --files Pillow" all my PIL and Pillow files show up.
I also tried to install cv2 using the directions posted here: http://www.mobileway.net/2015/02/14/install-opencv-for-python-on-mac-os-x/
import cv2
I get this as my error:
Python 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named PIL
>>> import Image
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named Image
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cv2
Any suggestions on what I am doing wrong?
I've been doing some hardcore research on this and finally got something to work. I may still have (accidentally) more than one python running, but i ran this command:
sudo easy_install http://dist.plone.org/thirdparty/PIL-1.1.7.tar.gz
And now "from PIL import Image" works!
I found this answer via this question regarding virtualenv. Though, I did not end up using virtualenv, it still led me to a resolution.
The problem with installing PIL using virtualenv or buildout
I spent the last few hours puzzling over a similar issue and finally was able to get modules to work by copying the file into the python library's folder where all the other modules are stored (I'm using anaconda).
Try double-checking where your modules are being installed to.

Astropy isn't working with Python

I've been having difficulty with Python recently, mainly since I think I had several versions and conflicts (due to Anaconda installs, canopy installs etc.). So I cleaned those out.
I reinstalled python (2.7) via brew.
I reinstalled numpy and matplotlib via pip.
I also reinstalled astropy and h5py via pip.
However, I get a clean import of numpy and matplotlib, but not of astropy and h5py:
~ > python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import matplotlib
>>> import astropy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named astropy
>>> import h5py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named h5py
>>>
My suspicion is that your pip executable is not linked to your python executable, which means when you run pip install astropy it is installing it in the site-packages for a different python.
One way to make sure you're using the correct pip is to not use
$ pip install astropy
but instead use
$ python -m pip install astropy
If this fails, it probably means that you don't have pip installed for the python instance you're using, and you need to install it (note that for Python 2 version 2.7.9 or later, or Python 3 version 3.4 or later, pip comes bundled with Python).
If this still doesn't work, then something stranger is going on. It may be due to having $PYTHONPATH or $LD_LIBRARY_PATH/$DYLD_LIBRARY_PATH set in a way that interferes with your python imports. In this case, you could clear these variables and try again. Otherwise, I'd consider using a package bundle such as conda or canopy. It makes these kinds of installation issues much smoother.
Edit: I see now that you've used conda and canopy, and you suspect these were causing your problems. Conda and canopy, by design, both sandbox their python installations so that they shouldn't get interference from other installs in your system, unless you force such interference by setting the environment variables I mentioned above. I'd suggest reinstalling conda and wiping those environment variables from your bash/csh startup script.

Pycuda installation on Ubuntu

I'm having a difficult time installing pycuda. I am running on Ubuntu 12.04. I first installed the Enthought python distribution (even though I already had python on the computer). I added the enthought python location to the path in my .profile (and this works without issue, typing python or ipython from the command line correctly uses the enthought version). I then followed the instructions from http://wiki.tiker.net/PyCuda/Installation/Linux/Ubuntu (skipping steps 0-1 as I already had numpy and cuda installed).
Everything seems to run and install fine. But when I try to actually use pycuda, it fails. For example, here's what happens when I try to run the hello_gpu.py example:
:~/Downloads/pycuda-2012.1$ python examples/hello_gpu.py
Traceback (most recent call last):
File "examples/hello_gpu.py", line 1, in <module>
import pycuda.driver as drv
File "/usr/lib/python_enthought/lib/python2.7/site-packages/pycuda-2012.1-py2.7-linux- x86_64.egg/pycuda/driver.py", line 2, in <module>
from pycuda._driver import *
ImportError: /usr/lib/libboost_python-py27.so.1.46.1: undefined symbol:
PyUnicodeUCS4_FromEncodedObject
Alternatively, when I try to import the pycuda package from idle, I get a different error:
Python 2.7.3 |EPD 7.3-1 (64-bit)| (default, Apr 11 2012, 17:52:16)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "credits", "demo" or "enthought" for more information.
>>> import pycuda
>>> pycuda
<module 'pycuda' from 'pycuda/__init__.pyc'>
>>> import pycuda.driver as drv
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pycuda/driver.py", line 2, in <module>
from pycuda._driver import *
ImportError: No module named _driver
I suspect part of the issue is me somewhere not specifying the correct path to the python interpreter, but I cannot figure out where this error occurs. Any suggestions would be most welcome, I am out of ideas.
This problem would appear to have been caused by conflicts between two different Python installations on the same system. The OP apparently solved this by uninstalling an Enthough Python installation and using only the system Python installation. There might well be other ways to solve this using a non-system Python installation, as suggested here
[This answer was assembled from comments and added as a community wiki entry in the hope it will receive a vote and be removed from the unanswered list for the PyCUDA tag]

Categories