I'm trying to use python with an excel document and trying to use pywin32 to access COM objects. My problem: I can't figure out install pywin32 so I can use it with iPython. Running the installer, it only detects my python27 installation and installs there.
When I run program with import win32com.client from cmd, it works fine. Trying to do the same in iPython and there is an ImportError. I'm pretty sure this is because their are two different system paths and win32com.client is only on one of them (sys.path in iPython only has things in C:\\Anaconda).
The iPython console is way easier to use than cmd for running and debugging programs, so I would really like to keep using it but I'm stuck.
You are correct that package installed to wrong python installation.
Also if you install pywin32 make sure you use the correct python when you install windows (unlike mac) allows you to run setup.py directly. This will use the 1st python in your path to determine install location.
Standard install:
python setup.py install
On windows the python is optional, but importantly still implied.
type:
where python
at command prompt to see which python will be used to run setup.py
You can also try:
/full_path/python setup.py install
Related
I am using Python 3.9 on Windows 10 which I downloaded directly from the Microsoft Store.
I tried running a script in PowerShell: Bash *.sh
This script is supposed to tell my computer to execute a .py script which uses scipy.io and many other modules.
Then I received this error:
ModuleNotFoundError: No module named 'scipy'
My strategy was to make sure pip was up to date, then use it to install the desired packages, then run some commands to see if the packages were installed.
I ran this command to update pip:
python3 -m pip install --upgrade pip
I ran this command to get some modules:
python -m pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose
I also tried this command just in case:
pip install scipy
and got the result:
Requirement already satisfied ...
I ran the command pip list to make sure scipy was in the list (and it was there).
Then I ran the command python and my prompt changed to ">>>" and entered import scipy and did not receive any errors.
I am very confused as to how I have scipy installed yet have my script tell me it isn't there. Please help!
From what you have posted it looks like you have more than one python environment path in your system, because of which when you are installing these libraries they are installed at certain location while when you run the bash script it is using some other python location.
Try using these commands in both your terminal (cmd in windows) as well as in you bash script:
import sys
print(sys.path)
This will give you the python environment path (location where your python libraries are present), then compare both the path you get from your terminal as well as bash. Add the path you got from the terminal to your global environment in order to make sure the same python version is used everywhere.
You can also refer to this: Python modules not found over terminal but on python shell, Linux
I had the same issue. You might have multiple versions of python and you only installed scipy on the one you are not using
OR
you are using an IDE which has the option to use packages you install that are not by default in python. Pycharm has that. When you make a new project, it has a tick option saying "Inherit global site-packages" which means it will use additional packages you have installed any.
I usually use PyCharm but, i was trying to run py extension file from terminal.
I have already installed opencv-python.
I tried pip3 install opencv-python also. Nonetheless, I am having the same issue. But, I am able to run those files from PyCharm.
It could be due to the fact that the terminal is using python2 version by default and you need to explicitly specify python3 while running the program to use python3.
You can see the link How Should I Set Default Python Version In Windows? to set your default python version to python3 in Windows.
I am trying to write a simple program that uses the numpy module. I have downloaded it without the use of a virtual environment using pip. On doing a pip freeze all the modules are present yet I am unable to import it when I use the command prompt python terminal. I found a few answers related to the environment variables but I can't work my way around it.
That can be caused by multiple python versions installed in your system.
So try:
python -m pip list
and if it does not list numpy, try installing it using:
python -m pip install numpy
In some cases, py works the same as python, so try all above things with py as well, including your own attempts
I've been trying to use 'pip' in the Python shell - something that should be very simple. I am told by everyone that all I need to do is to open the shell and call:
pip install <name-of-some-package>
Output:
NameError: name 'pip' is not defined
After peeking into the Scripts folder where 'pip' is supposed to live, I notice that it is not really a .py but a .exe. 'easy_install' also suffered the same fate. They were installed together with the Python standard distribution from python.org.
Why is pip installed as a binary file? Can I get it as a module so I can run it from the Python shell?
pip.exe is just a thin binary wrapper (a Setuptools wrapper to be exact) that ends up doing loading the pip package's entry point. It's installed when you install pip. On Unixes, like Linux or macOS, the "executable" is actually just an executable Python script, but does the same thing.
You can do python -m pip too, which is (practically) equivalent to running the pip (or pip.exe) wrapper. (Note this may not hold for other packages, but it does for Pip.)
import pip will also work; the actual guts of Pip exist in your Python's lib/site-packages folder.
If you want to run pip from python shell you have to use python commands, not shell commands.
Try this:
from pip._internal import main
main(['install', 'requests'])
So I'm trying to install via cmd using a setup.py file..
However, when I try to install it through CMD, this happens:
The first way you were trying to install it is correct python setup.py install, however you need Python 2.x for this installer to work. You are in a Python 3.2 environment and it appears that this module has not been updated to work with Python3 at this time.
http://ocemp.sourceforge.net/manual/installation.html
The print bdist.bdist_base, self.install_dir statement is Python 2.x syntax. If it were compatible with Python3, it would be print(bdist.bdist_base, self.install_dir)
----------
If you require development in both Python3 and Python2, I highly recommend installing Anaconda
https://www.continuum.io/downloads
You can set up multiple environments with whatever versions of Python that you want. Then you can activate each one as necessary.
http://conda.pydata.org/docs/py2or3.html