How do I determine which version of the python module 'time' is installed. For other modules .version.version or .__version__ work, however for time, both these methods return the error 'module' object has no attribute 'version' or 'version'
Module time is built-in in the Python interpreter. No other version than the interpreter's itself can be a valid answer (you can access that one using sys.version).
Other built-in modules like os, sys etc. also do not have their own version information.
Related
I tried the below code in Anaconda Prompt
import <module name>
print(<module name>.__version__)
print(<module name>.version.VERSION)
print(<module name>.version)
but get AttributeError: 'module' object has no attribute 'version' for each print.
Is it be'cos datetime, math, win32com.client are in-built library in Python? So how do I find their version?
Thank you
You can find the version of these modules in the Python3.x/Lib/__pycache__ folder.
As mentioned in the docs the version is available in this format module.version.pyc
Example: datetime.cpython-39.pyc means version 3.9
In fact, the version of the built-in modules is the same as the version of python.
Whenever I try to just import winappdbg it gives me an error ModuleNotFoundError: No module named 'breakpoint'. So, I tried installing breakpoint and that gives me another error ModuleNotFoundError: No module named 'ConfigParser' and I've installed configparser several times and still get the error. (Can't find capital ConfigParser) I'm using Windows 10/PyCharm Community Edition 2017.2.3/python 3.6.3
WinAppDbg is only for Python 2.x, it does not work on Python 3.x. Honestly, I had no idea it would even let you import it.
All those import errors are happening not because of missing dependencies (also, no idea there were similarly named modules in pip), they are submodules of WinAppDbg itself. Since Python 3 has a different syntax to specify those, it tries to load them as external modules instead. I suppose you could fix that in the sources by prepending a dot before every submodule import, but I'm guessing more stuff would break down the road (string handling for example is radically different and that would affect the ctypes layer).
TL;DR: use Python 2.x.
I want to create a new file in Python for that I am using mknod command, but getting error as:
os.mknod();
AttributeError: module 'os' has no attribute 'mknod'
I am using windows and attributes other than 'mknod' are working.
os offers functionality that is closely related to the OS you're using. If most other attributes can be accessed from os (meaning you haven't got a os.py file in the current dir masking the standard module) an AttributeError will 99% signal an unsupported function on your Operating System.
This is what the case is with os.mknod on Windows. Creating named pipes in Windows has, as far as I can understand, very different semantics.
Either way, if you are trying to use mknod to create named pipes you'd probably be better using mkfifo() (again, only Unix supported) . If you're using it to create ordinary files, don't, use open() which is portable.
I'm trying to do a linear regression using scipy.stats.linregress(). However when I run my script, i get the error message
AttributeError: 'module' object has no attribute 'stats'*
I'm using the Anaconda python 2.7 distribution which in its documentation says to have the module installed. Anaconda documentation
In the python interactive interpreter, I can import the scipy module, but can't find stats. When I look up its __version__ it says 0.14, which should have the stats module..
I really can't guess why the stats is unavailable..
This error:
AttributeError: 'module' object has no attribute 'stats'
Means what it says. There is no attribute named stats in the scipy module.
Not because no such thing exists on disk, but because no such thing has been imported—because you never even tried to import it.
scipy is a package. As the Python tutorial explains, importing a package doesn't import all of its submodules.
Some packages have a __init.py__ that automatically imports some or all packages.* But that would be a bad idea for scipy, because there are a ton of them, so it would take some time to import all of them, and usually you only need one or two in a given project.
So, you just need to do this:
import scipy.stats
* There are also some cases like os which fake being packages but aren't, so you can use os.path without importing it, or cases like pyobjc that create special placeholder objects for their modules that automatically import the real modules when first accessed.
I get the same error when I import scipy instead of scipy.stats. Have you tried
import scipy.stats
scipy.stats.linregress()
The following is my code.
import http
h1 = http.client.HTTPConnection('www.bing.com')
I think it's ok.But python give me the following error:
AttributeError: 'module' object has no attribute 'client'.
I wanted to know why and how to fix it.Thanks.
First, importing a package doesn't automatically import all of its submodules.*
So try this:
import http.client
If that doesn't work, then most likely you've got a file named http.py, or a directory named http, somewhere else on your sys.path (most likely the current directory). You can check that pretty easily:
import http
http.__file__
That should give some directory like /usr/lib/python3.3/http/__init__.py or /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/http/__init__.py or something else that looks obviously system-y and stdlib-y; if you instead get /home/me/src/myproject/http.py, this is your problem. Fix it by renaming your module so it doesn't have the same name as a stdlib module you want to use.
If that's not the problem, then you may have a broken Python installation, or two Python installations that are confusing each other. The most common cause of this is that installing your second Python edited your PYTHONPATH environment variable, but your first Python is still the one that gets run when you just type python.
* But sometimes it does. It depends on the module. And sometimes you can't tell whether something is a package with non-module members (like http), or a module with submodules (os). Fortunately, it doesn't matter; it's always save to import os.path or import http.client, whether it's necessary or not.