cannot import name module with module correctly installed - python-2.7

new in python.
I have python 2.7.
I just installed a new module (beatifulsoup) from cmd in windows 7 which is correctly installed : When I enter the python consol from the cmd I can import succesfully bs4 without error.
My problem is that I cannot import it when I am using Aptana studio. Or if I code it in sublimetext and save it as a py file, when I run it I get the error message "cannot import name beautifulsoup 4". I don't get why? Is it a problem of pydev environment on aptana? If yes how can I add modules to Aptana and sublimetext3 ?

Are you trying to import like this:
from bs4 import BeautifulSoup
If not, try it that way. Hope this helps!
(Perhaps you should add your import statement to the question so we can see if there is a problem with the statement or if the issue resides somewhere else)

Related

Caffe Framework :Importing Error

I followed the instructions from "https://gist.github.com/nikitametha/c54e1abecff7ab53896270509da80215" and installed caffe framework.
But ,when I import caffe from some other directory ,it is showing this error
caffe framework was installed but, it still shows the import error -
No module named caffe
How to solve this issue?
Thank you...
You need to add ~/caffe/python to your $PYTHONPATH. either
~$ PYTHONPATH=$PYTHONPATH:~/caffe/python python
>>> import caffe
Or you can do it inside python
>>> import sys
>>> sys.path.insert(0, '~/caffe/python')
>>> import caffe
Alternatively, you can modify your ~/.bashrc file and fix PYTHONPATH environmet variable there

ImportError: No module named vaderSentiment

I'm trying to run a code in python2.7 on windows os that uses sentiment analysis
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
analyzer = SentimentIntensityAnalyzer()
and I'm getting this error
ImportError: No module named vaderSentiment
Can anyone help me with this?
Assuming you solved this one as it's from 7 months ago, but for anyone else searching for it:
Go into terminal/cmd and paste the following:
pip install vaderSentiment
More info on VADER: https://github.com/cjhutto/vaderSentiment
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
#note: depending on how you installed (e.g., using source code download versus pip install), you may need to import like this:
#from vaderSentiment import SentimentIntensityAnalyzer
read the comment in a code
Try running your file with Python3 instead of just python. Sometimes when you have different pips/pythons installed on your computer you might have vaderSentiment installed in python2 when you need to run it in python3.

No module named kivy.app

So I thought I'd toy around and try and learn Kivy, as it looks interesting. I have just started trying to get one of their examples working:
from kivy.app import App
from kivy.uix.widget import Widget
class MyPaintWidget(Widget):
pass
class MyPaintApp(App):
def build(self):
return MyPaintWidget()
if __name__ == '__main__':
MyPaintApp().run()
I get the following error:
C:\Kivy-1.8.0-py2.7-win32>python paint.py
Traceback (most recent call last):
File "paint.py", line 1, in <module>
from kivy.app import App
ImportError: No module named kivy.app
I have installed the latest version of Kivy. I see "app.py in the C:\Kivy-1.8.0-py2.7-win32\kivy\kivy folder.
Also, here is my PYTHONPATH:
>>> import sys
>>> for n in sys.path:
... print n
...
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\site-packages\setuptools-2.0.1-py2.7.egg
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\site-packages\pywin32-218-py2.7-win32.egg
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\site-packages\plyer-1.1.2-py2.7.egg
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\site-packages\kivy_garden-0.1.1-py2.7.egg
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\site-packages\requests-2.2.1-py2.7.egg
C:\Kivy-1.8.0-py2.7-win32\Python27\python27.zip
C:\Kivy-1.8.0-py2.7-win32\Python27\DLLs
C:\Kivy-1.8.0-py2.7-win32\Python27\lib
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\plat-win
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\lib-tk
C:\Kivy-1.8.0-py2.7-win32\Python27
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\site-packages
Any help would be greatly appreciated. Thank you.
I ran into this error message when I named the script kivy.py, because python looks first in the current directory to fill the dependency, so it never sees the real kivy package.
Renaming the script fixed it for me.
The name of the folder or file cannot be kivy or kivy.py. You need to rename it to another name and it will run ok.
So, I figured it out....I was not being very smart. I'm new to Kivy and I'll answer this for anyone else that is as green as I am. You can't just run this as a python program, doh.
Follow instructions [here] (http://kivy.org/docs/installation/installation-windows.html#start-a-kivy-application) and all will be right with the world.
If you installed kivy using pip you need to add the packages to your environment. In Windows Command Prompt do
pip show kivy
~Take note of the Location of the module.
Next you can do 1 of two things.
Configure any python files you write to refer to the location of your module with sys, use this tutorial for more info: https://kivy.org/docs/guide/environment.html
Add the location you found above to your PATH (Windows): https://www.computerhope.com/issues/ch000549.htm
2 Worked for me.
I was also facing the same issue while running sample app.
I followed simple steps given in : https://kivy.org/doc/stable/gettingstarted/installation.html#install-pip
It worked for me.
Create the virtual environment
Activate the virtual environment.
Install Kivy
run your .py file
I know I am too late but I hope this will help others, I just did not run it from the command prompt, I opened the python code in my python shell and then pressed run 'F5' and it worked for me.
If you're using a virtual environment (venv), make sure you're targetting the the correct Python interpreter. See here for how to to change to the venv interpreter in IntelliJ

Pygame missing modlues

Im completely new to pygame. after installing it and looking at a tutorial, the first code block i ran (from the tutorial) took me to the pygame modlule, and said that pygame.base could not be found.
it couldn't find any of these at all:
from pygame.base import *
from pygame.constants import *
from pygame.version import *
from pygame.rect import Rect
from pygame.compat import geterror
import pygame.rwobject
import pygame.surflock
import pygame.color
that's from the pygame module.
I looked in both the pygame files that were installed and saw files with those names, though i could not open them (unknown file type)
i installed the python 2.7 binary for windows version of pygame, and used the installer. everything looks like it's in the right place as far as i can tell.
It doesn't seem that you have pygame properly installed. Can you even successfully run import pygame?
Are you sure you only have one copy of python installed?

Matplotlib and WSGI/mod_python not working on Apache

Everything works as supposed to on the Django development server. In Apache, the django app also works except when matplotlib is used. Here's the error I get:
No module named multiarray.
Exception Type: ImportError
Exception Value: No module named multiarray
Exception Location: /usr/share/pyshared/numpy/core/numerictypes.py in <module>, line 81
Python Executable: /usr/bin/python
Python Version: 2.6.4
From the python shell, both statements work: import numpy.core.multiarray and import multiarray. Any ideas?
Thanks
As I'm looking over the numpy files, I found the multiarray module, which has an extension of 'so'. My guess, is that mod_python is not reading these files.
Problem solved. Here's what I did.
First of all, before I was getting the import error:
"No module named multiarray."
I was getting an error like this:
": Failed to create /some/dir/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data"
By adding the pyshared folder to the PythonPath variable, this error went away and I got the import error.
So here's how I fixed it:
Removed the pyshared folder from the PythonPath variable.
Before importing the matplotlib module, add these lines:
import os
os.environ['HOME']='/some/writable/dir'
Next, before import matplotlib.pyplot or pylab, add these lines:
import matplotlib
matplotlib.use('Agg')
# 'Agg' or whatever your backend is.
This is documented here.
That's is! It's working on python2.5 for me now. But I believe it'll work on 2.6 as well.
On Win32 I solved a similar problem (not being able to load pyd modules through ISAPI_WSGI (IIS)) by downgrading from py2.6.5 to py2.5. It seems like this might be a Python bug that has been re-introduced. See for example this discussion.