I have installed python 2.7 and trying to run below code which always gives error:
# !/usr/bin/python
import os, sys
stinfo = os.statvfs("C:\Tools")
And error comes as :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'statvfs'
Any clue to make it work?
I'm assuming from your example file path that you're using Windows.
The os.statvfs() call is not supported in Windows. An attempt to add support was made, but was rejected.
You might find this answer helpful for possible solutions.
Make sure you are running in python2.7
import sys
print(sys.version)
Also you should escape a backslash
EDIT: See Mikes answer, did not know this is not implemented for Windows. Using it is also not wise because it is deprecated since Python2.6 and has been removed in Python3
Related
I tried to download Graphlab from Turi wit the following tutorial. I coded with their tools and tried to compute a Python script but it answered me an ImportError.
(gl-env)ubuntu#ip-172-hey-hey-hey:~/Eclipse-Stats$ source deactivate
discarding /home/ubuntu/anaconda2/envs/gl-env/bin from PATH
ubuntu#ip-172-hey-hey-hey:~/Eclipse-Stats$ unset PYTHONPATH
ubuntu#ip-172-hey-hey-hey:~/Eclipse-Stats$ python Main.py
2017-07-27 14:56:00.520425
/home/ubuntu/.local/lib/python2.7/site-packages/sklearn/cross_validation.py:44: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.
"This module will be removed in 0.20.", DeprecationWarning)
Traceback (most recent call last):
File "Main.py", line 3, in <module>
import prediction
File "/home/ubuntu/Eclipse-Stats/prediction.py", line 1, in <module>
from graphlab.toolkits.recommender import ranking_factorization_recommender
ImportError: No module named graphlab.toolkits.recommender
Actually it cames often on the server when I tried to download with pip numpy, scipy, sklearn... Like we can see in the following conversation (in Spanish) between FJSevilla and the man of my team I'm working with.
Two things: (1) check the version of your Python console and see if it matches or is higher than the compatibility with the packages. If you look at the depreciation message and read it through, you would understand what is going on a little more. (2) be careful of what you are importing and how you import them because your formatting might also be a syntactic all error. One thing you could do is find the package, manually download, unzip, then run the setup.py.
Traceback (most recent call last):
File "game.py", line 6, in
import random, pygame, sys
ImportError: No module named pygame
im no expert but from my experience but make sure you downloaded the right pygame for 1. your version of python and 2. your system+(32/64 bit).
also make sure in your path you have c:\python27 , c:\python27\scripts.
I have successfuly installed csvkit using conda install ...
However, when I try to import the libraries in Python 2.7 Spyder, I get error messages:
import csvsql
Traceback (most recent call last):
File "<ipython-input-5-303a60a6b1ac>", line 1, in <module>
import csvsql
ImportError: No module named csvsql
import csvkit
Traceback (most recent call last):
File "<ipython-input-7-ca8a99ae9834>", line 1, in <module>
import csvkit
ImportError: No module named csvkit
I looked at the documentation -- they describe the installation process but not how the library is loaded in Python.
Moreover, I had an analogous problem with httplib2. I installed it successfuly but when I tried to import it in Spyder I received an analogous error message (No module named httplib2).
(I use Anaconda 3 and Spyder on Windows 11)
Any ideas? Thank you in advance.
I asked this question on the csvkit GitHub / issues forum.
The answer given was: You should use agate on which csvkit now relies for all its operations. See https://github.com/wireservice/agate.
I'm with you -- it would be wonderful to use csvkit as a command-line tool and a library, but it's authors don't see it that way. The full issue: https://github.com/wireservice/csvkit/issues/670
I have installed Scapy on my OS 10.11.5 machine and have been playing around with it in the interactive mode while reading through some of the tutorials on their site (http://www.secdev.org/projects/scapy/doc/index.html) and it's working just fine.
I can run sudo scapy and then run the sniff(count=5) command and all works fine; it does a nice and pretty job printing the contents with _.show(). All works, except a weird message:
WARNING: __del__: don't know how to close the file descriptor. Bugs ahead ! Please report this bug.
But that's neither here nor there as all things work to properly play with the packets (I haven't tested sending anything while watching in Wireshark, but I guess that's a topic for another time).
Now... When I try to do the following code in a .py file, I get all kinds of issues:
#!/usr/bin/python
from scapy.all import *
def packet_calback(packet):
print packet.show()
sniff(store=0, prn=packet_callback)
with a sudo scapy.py, I get the follow traceback:
#:./scapy.py
Traceback (most recent call last):
File "./scapy.py", line 3, in <module>
from scapy.all import *
File "/Users/myuser/Desktop/scapy.py", line 3, in <module>
from scapy.all import *
ImportError: No module named all
From what I see in the docs, this is the preferred method to getting it to work, but it doesn't here...
I have tried import scapy and then scapy.sniff(...) and scapy.all.sniff(...) but those don't work either.
Just for officialness:
$which python
/usr/local/bin/python
$python --version
Python 2.7.11
$/usr/bin/python --version
Python 2.7.10
I guess I also have 2 versions of Python installed.... But the same issues happen with both installs.
Help! Please?
Wow... I'm an idiot...
Lesson to all! Don't name your file after a module you're importing! I know better than this and yet look at what I've done!!
Bah!!
i have installed matplotlib using pip in ubuntu 14.04 LTS.. but on running dispersion_plot this is showing the following error ..
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/nltk/text.py", line 455, in dispersion_plot
from nltk.draw import dispersion_plot
ImportError: cannot import name dispersion_plot
I am new to python... can anyone suggest if there is a better way of installing matplotlib in nltk.
The examples of the online book are not quite right.
You may try this:
from nltk.draw.dispersion import dispersion_plot
words = ['Elinor', 'Marianne', 'Edward', 'Willoughby']
dispersion_plot(gutenberg.words('austen-sense.txt'), words)
You may also call it from a text directly:
from nltk.book import text1
from nltk.draw.dispersion import dispersion_plot
dispersion_plot(text1, ['monstrous'])
this way you import the function directly instead of calling the funcion from text object.
I realized this watching at the source code directly.
Hope this work for you
After importing it using spyder, this is how the plot would look.