This question already has answers here:
Python Interpreter Mode - What are some ways to explore Python's modules and its usage
(3 answers)
Closed 8 years ago.
OS Windows XP SP3
situation
I installed three python exes on my machine.
Python 2.6
Python 2.7
Python EPD ENABLED (for pylab)
problem
I installed wxPython and in the selection I decided to install it to Python in system registry
I don't know to which python this package was installed.
what I tried
I tried writing import wx on all the shells and found that it was installed to EPD python.
bigger issue
I don't want to keep doin this each time I install a package. So is there a command that can be used in the shell or any other way, so that I can know about all the packages installed?
please help me with this issue.
Type help() in the shell. And then in the help prompt type modules to see a complete list of all modules.
You can get a complete list with sys.builtin_module_names and pkgutil.walk_packages():
import pkgutil
import sys
print sys.builtin_module_names + [name for module_loader, name, ispkg in pkgutil.walk_packages()]
The modules subcommand of help() puts a friendlier interface on top of these results.
Related
This question already has answers here:
PyCharm error: 'No Module' when trying to import own module (python script)
(17 answers)
Closed 1 year ago.
I am using PyCharm and am having trouble importing modules
I set up a venv and imported the dependencies via pip install -r
When I try to run the application and get 'module not found' for all imports.
If I open a terminal in PyCharm and do pip list all the required modules are listed
Further PyCharm can file the modules - I can perform completion when typing the name of the module.
What else can I try?
Sounds like you have more than one python environment on your machine.
So, in my opinion, you need to manage the environments in python IDE.
The same happened to me so this helped me in that.
Do check: https://docs.python.org/3/tutorial/venv.html
You can also seek help from the below article:
https://www.freecodecamp.org/news/manage-multiple-python-versions-and-virtual-environments-venv-pyenv-pyvenv-a29fb00c296f/
I solved this by checking the boxes 'Add content toots to PYTONPATH' and #Add source roots to PYTHONPATH'
I'm more specifically wanting to know whether sqlite3 and json comes with python IDLE or do I have to install them separately to use them inside IDLE, If so can anyone link me to those installing procedures of sqlite3 and json on Python IDLE?
I also want to know where I can find the list of other pre-installed packages that comes with basic Python IDLE (i.e. Python 2.7.14) . I am a Beginner and it would be really helpful.
Thank you.
To get a list of your packages, from your terminal, launch python :
python
Then
help("modules")
Another solution, if you want to check if json or sqlite3 are installed, start Python from your terminal :
python
Then import sqlite3 and json:
import json
import sqlite3
You can check theirs version with :
>>> json.__version__
'2.0.9'
>>> sqlite3.version
'2.6.0'
IDLE is part of the CPython standard library and is usually installed when tkinter (and turtle) are. It provides an optional alternate interface for running your code with a particular python binary. When you run code through IDLE, it is run by the python binary that is running IDLE. So the same modules are available whether you run code through the terminal interface or through IDLE. There is no separate installation.
This question already has answers here:
ImportError: No module named 'pygame'
(25 answers)
Closed last year.
I installed python(2.7) using anaconda on an ubuntu machine.
I installed pygame.
When I import pygame I get the error:
ImportError: No module named pygame
Interestingly, when I use /usr/bin/python,
the interpreter now gives no error for import python.
My code file has to run by command python x.py, not in te interpreter.
How could I resolve the issue?
Many Thanks.
Which version are you using? You most import pygame to a Python 2.7 shell.
http://pygame.org/download.shtml is for https://www.python.org/ version 2.7. Make sure you have downloaded and made the setup for Python 2.7 before you coming over and import pygame. If you have followed my steps, I hope you will see:
>>>
Pygame only works for python 2.7 and down. If you downloaded a later version make sure you go into setting in pygame and make sure you have selected python 2.7 to run. You can also do this by making a new project and when you name it scroll down to base interpreter and select python 2.7 since pygames will most likely have selected a higher version of python which will not work for pygames
I am running PortablePython_1.1_py2.6.1 on a USB stick. My code relies on some modules that are not preinstalled. Does anyone know whether it is possible to add new modules to a portable python installation? Simply copying in folders into site-lib does not seem to work.
What does import sys; print sys.path say? It should be the list of directories and zipfiles where Python (portable or otherwise) looks for modules to import. Just copy your modules into one of those directories or zipfiles, or sys.path.append('/whatever/dir') if you have your modules in /whatever/dir and want to keep them there (the latter approach will last only for the current session, be it interactive or a script's execution).
This closed question was actually asked for Portable Python 3.2. I have found a nice way to install modules with Windows :
download the zip archive of the distribute module
install it by typing
MyPythonPath\App\python MyDownloadPath\setup.py install
in a DOS commander
Now Easy Install is installed in folder MyPythonPath\App\Scripts. So type e.g.
MyPythonPath\App\Scripts\easy_install-3.2 numpy
to install the numpy module.
This question is old and maybe this is a possibility that was not possible at this time but simply:
From a command prompt go to your Portable Python's python.exe folder with cd <path to Portable Python>\App\Python,
Run (for instance to install selenium module): .\python.exe -m pip install selenium,
Now you have selenium module installed, you can check in your <path to Portable Python>\App\Python\Lib\site-packages that you have now selenium and its dependencies.
This question already has answers here:
Find full path of the Python interpreter?
(3 answers)
Closed 6 years ago.
Basically I want to get a handle of the python interpreter so I can pass a script file to execute (from an external application).
This works in Linux & Windows:
Python 3.x
>>> import sys
>>> print(sys.executable)
C:\path\to\python.exe
Python 2.x
>>> import sys
>>> print sys.executable
/usr/bin/python
sys.executable is not reliable if working in an embedded python environment. My suggestions is to deduce it from
import os
os.__file__
I think it depends on how you installed python. Note that you can have multiple installs of python, I do on my machine. However, if you install via an msi of a version of python 2.2 or above, I believe it creates a registry key like so:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Python.exe
which gives this value on my machine:
C:\Python25\Python.exe
You just read the registry key to get the location.
However, you can install python via an xcopy like model that you can have in an arbitrary place, and you just have to know where it is installed.