Find path of a package (e.g. pandas) in Python [duplicate] - python

This question already has answers here:
How to retrieve a module's path?
(23 answers)
Closed 2 years ago.
Is there a way to programmatically find the location of a python package once it is imported?
For example:
import os
import pandas
os.get_package_directory(panda)
>>> C:\Users\username\miniconda3\pkgs\pandas-1.0.5-py37h47e9c7a_0

It's been a while since I've done this, but try this:
import pandas
print(pandas.__file__)

Related

How to import files/modules from other directory in python? [duplicate]

This question already has answers here:
How can I import a module dynamically given the full path?
(35 answers)
Closed 3 years ago.
I want to import some files/modules from other directory.
I have placed an init.py in the directory but still not able to import the files/modules.
I am using Pycharm 2019.
I want to use init.py only method and not the sys.path.append.
thanks in Advance!
there are multiple ways to do that, I'll name two -
import sys
sys.path.insert(0, 'path/to/your/py_file')
import py_file
is relatively easy, and another one is if you're using pycharm just mark the directory of which you want to import from as a sources root.

Python: How to list imported modules [duplicate]

This question already has answers here:
How to list imported modules?
(10 answers)
Closed 3 years ago.
In Python calling the import function brings in a module to give a program access to its namespace of classes, functions and variables.
import os
import sys
print(os.name)
print(sys.implementation)
Is there a way to list which modules have already been imported in a program?
>>> list_imports()
sys
os
And if so, is there a way to figure out the version of the imported module?
sys.modules is the closest you'll get. Modules following spec will have a __version__ attribute.
Just use sys library
import sys
sys.modules.keys()

The dot in module import (python 3.x) [duplicate]

This question already has answers here:
What does a . in an import statement in Python mean?
(3 answers)
Closed 4 years ago.
For what i can use the "." in import module. I meet it in sklearn library. It looks like:
from .externals import six
The . is a shortcut that tells it search in current package before rest of the PYTHONPATH. So, if a same-named module Recipe exists somewhere else in your PYTHONPATH, it won't be loaded.

Win32 vs Win32api [duplicate]

This question already has answers here:
Python 3.4 :ImportError: no module named win32api
(7 answers)
Closed 6 years ago.
I downloaded pywin32 (using pip), and want to use the win32api, however, the module doesn't exist. win32 exists and win32com exist, but not win32api. How can I access win32api(specifically I want to be able to access the GetVolumeInformation) function.
Figured it out, win32api is part of win32, so I just changed the import to win32.win32api.

How to change C drive to F drive using python Script [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to set the current working directory in Python?
How to change C:\> to F:\> using Python
I tried
import os
os.chdir("F:")
but got an error.
You need the extra backslash:
import os
os.chdir("F:\\")

Categories