How to install modules using IDLE [duplicate] - python

This question already has answers here:
Installing python module within code
(12 answers)
Closed 3 years ago.
I have some code that uses modules that are not installed by default (eg. Numpy), and I want to give the program to a friend of mine who does not have that module.
I do not want him to have to go through the tedious process of using cmd to install the module. Is there any way to install the module from within the code itself? Like:
import pip
pip.install('numpy')
(completely hypothetical)
BTW: I am using Windows 10

from subprocess import call
module=input('Name module: ')
try:
call(['pip', 'install', module])
except Exception:
print('Error')

Related

Cannot run Python module [duplicate]

This question already has answers here:
How to use 3to2
(4 answers)
Closed 11 months ago.
I am trying to run the Python 3 module '3to2' on Windows 10. Here is part of my pip3 list:
Package Version
----------------------------- -----------
3to2 1.1.1
I am trying to execute it with py -3 -m 3to2, but am receiving this:
C:\Users\Ben Bistline\AppData\Local\Programs\Python\Python39\python.exe: No module named 3to2
I think it has something to do with my Python Path, but I am unsure.
Thanks!
There is no module called 3to2. Module names can't start with a digit. Instead, there should be a standalone file in your "...\Programs\Python\Python39\Scripts"
directory called 3to2.py. That's what you need to run.

python module not found even though it is installed [duplicate]

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'

How to download a module from Github [duplicate]

This question already has answers here:
PIP install a Python Package without a setup.py file?
(2 answers)
Closed 5 years ago.
I am new to python and I am having trouble downloading a module from GitHub: https://github.com/petercerno/good-morning
I have looked online for solutions, but each solution I try does not work. I have tried:
pip install https://github.com/petercerno/good-morning.git
I get an error that says, "Cannot unpack file" & "Cannot determine archive format." I have no idea why I am getting this error.
Just save good_download.py and good_morning.py to the same directory as your Python script, and then import them:
import good_morning
import good_download
# do stuff!

What all packages do I have? [duplicate]

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.

How to get the python.exe location programmatically? [duplicate]

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.

Categories

Resources