I'm running 32-bit Windows XP and trying to have Matlab communicate with Cgate, a command line program. I'd like to make this happen using wexpect, which is a port of Python's module pexpect to Windows. I'm having trouble installing or importing wexpect though. I've put wexpect in the folder Lib, along with all other modules. I can import those other modules but just not wexpect. Commands I've tried include:
import wexpect
import wexpect.py
python wexpect.py install
python wexpect.py install --home=~
wexpect install
Does anyone have anymore ideas?
If you installed wexpect somewhere in the module search path (sys.path), then import wexpect is what you would use. You have to make sure you installed it in the right path, though (the usual location is Lib\site-packages inside the Python installation.) If the package wexpect.py was in came with a setup.py file, you could install it with
\path\to\python setup.py install
from a DOS prompt. Depending on what else you did you may need to restart the Python interpreter or IDE that you're using for it to pick it up. You should also pay attention to the errors you get when you try import wexpect, as it may have dependencies you need to install.
Perhaps you haven't installed wexpect correctly.
In your command prompt (not python, but the DOS-like command shell), go to the directory where you downloaded wexpect. Make sure it's unzipped and you can see the setup.py file when you use the dir command.
Then enter the command (again, in the cmd shell, not the python terminal):
python setup.py install.
I have created a Github repo and PyPI project for wexpect. So now wexpect can be installed with:
pip install wexpect
Related
I am trying to install the python package us without admin privileges.
I have tried pip install us in Anaconda prompt to no avail.
I have also tried the suggestion listed here: Install python modules on windows without admin rights--didn't work.
I have now downloaded the files from the site https://pypi.org/project/us/ to my desktop and need to know how to install the package from here.
I am using the Spyder IDE and Python 3.7. Is there a way to do this?
Thanks.
I do this on the daily and if I understand what you are saying you are doing it right. If pip install us in command prompt or shell (if you are using Windows OS) doesn't work try py -m pip install us. Make sure you are using command prompt and not using your IDEz
As you can see it worked first try for me.
Since you have downloaded the files, Extract them in a folder and normally a setup.py file must be include, open command prompt in that folder and run :
python setup.py install
I'm trying to install new python modules on my computer and I know how to install through the terminal, but I wish to know if there is a way to install a new module directly through VSCode (like it is possible on PyCharm)?
I already installed through the terminal, it isn't a problem, but I want to install without be obligate to open the terminal when I'm working on VSCode.
You should open the terminal inside the VSCode and install the modules you want.
something like👇
if that's not you meant, please let me know.
First of all I would advise you to select the current Python version you have. It has been explained here:
VSCode: There is no Pip installer available in the selected environment
Next, you should check is the pip installed in your Python main directory or not, by checking how to do on this website:
https://pip.pypa.io/en/stable/installing/
or this thread
How to use pip with Visual Studio Code
by typing
py -m pip
in your terminal, like
C:\Users\m\Desktop\Python> py -m pip
You should have the list of commands and general options which can be used. One of them is install
On the Python library platform, you always have the command to be copied in order to the installation of package you want.
In your terminal, the initial command should look as:
PS C:\Users\m\Desktop\Python> py -m
to which you should append the command prepared on the Python library platform (by copying it and pasting).
C:\Users\m\Desktop\Python> py -m pip install openpyxl
That's it. The package should be installed in your Python folder, what you will see in the terminal.
If everything is alright, you just need to type
import openpyxl #or other package name, which you downloaded
and use it!
Unfortunately! for now, only possible way is terminal.
I'm trying to make my first UniCurses project with Python on OpenSUSE.
I put the import statement in my .py file, but when I tried to run it, it says the module is not there... So I downloaded UniCurses from the website, and the instructions say Unix's Python already has UniCurses. That's odd, but I continued. I put the downloaded unicurses.py into my project directory, and when I tried running my file, an error message says UniCurses is not compatible with my system, and that either my Python distribution is below v2.6 or my operating system is something other than Windows or a *nix. My Python is v2.7.8, and again, my OS is a Linux distro. Why is this happening, and what should I do?
Edit: It's worth noting that the regular curses supposedly doesn't work on my system either.
Answer by Sagar Rakshe from How to install Python package from GitHub:
To install Python package from github, you need to clone that repository.
git clone https://github.com/jkbr/httpie.git
Then just run the setup.py file from that directory,
sudo python setup.py install
If you have already downloaded the file you can skip the first step and just run the python setup.py install in the folder. (I don't think sudo is necessary for python)
I am running Windows and am a beginner python user trying to install a few modules to run a python script. I have Python 2.7.9 and 3.4.2 both installed to the C:\ directory. I downloaded matplotlib-1.4.3.win-amd64-py3.4.exe and the corresponding .exe for python 2.7 from the Matplotlib website, but when I run the py3.4 exe the program cannot find Python 3.4 to update (Cannot install: Python version 3.4 is required, which is not found in the registry).
Python 2.7 installer works perfectly. Is there a misset PATH variable in Windows I can modify so the .exe can function properly? In CMD 'Python --version' returns Python 3.4, so unsure how to fix the issue. I installed these months ago, and may have put them in Downloads before transferring both to C:\ for clarity, which may be the problem but am unsure how to fix it.
Also, if your answer involves pip in any way please clarify how exactly to use pip in Windows. A lot of websites say to run eg. 'pip setup.py install' in the 'terminal' but do not specify if they mean Windows CMD terminal, IDLE GUI, or Python.exe command-line interface. Thanks a lot!
Not the answer to your actual question, but some clarification on your last point:
but do not specify if they mean Windows CMD terminal, IDLE GUI, or
Python.exe command-line interface.
Yes, this requires to know some context that a beginner may not have. The command pip is always used in the CMD terminal. So open CMD, and enter
pip3 install matplotlib
Notes:
Use pip3 when installing for Python 3. Then you're certain you're not accidentally installing libraries for Python 2.
pip setup.py install does not exist. You're mixing up two mechanisms to install Python packages/libraries:
One uses pip, with aforementioned pip3 install <something>. Pip goes looking online, finds a corresponding package name in a database, retrieves the URL for that package, downloads the package and installs the package. All in one command.
python3 setup.py install (again explicitly use python3 or python2 to be sure) requires you to find the package, download it, unzip it, and then in the CMD terminal, inside the unzipped folder, run the python3 setup.py install command.
This second method is usually for the latest-greatest version of a package that is not yet in pip's database, or for packages that never were in pip's database in the first place.
Generally, as a beginner, you want to stick with pip. If you ever run into the issue with the package not being available via pip, you may still be able to use pip for downloading and installing, like for example so:
pip install https://github.com/matplotlib/matplotlib/archive/master.zip
which would install the most recent matplotlib (which won't have even a version number yet, so bugs could be around).
All of these commands happen in the CMD terminal: downloading/installing packages generally all go through the terminal.
Also, when people mention "terminal", they will mean (for Windows) something like the CMD terminal. When it has to be done inside Python, it is generally called the "Python prompt". (IDLE is yet a different beast, that I'm not familiar with. I'm guessing that it has several parts, including a text editor section and a Python prompt section.)
I'd like to make a switch from Windows to Linux (Ubuntu) writing my python programs but I just can't get things to work. Here's the problem: I can see that there are quite the number of modules pre-installed (like numpy, pandas, matplotlib, etc.) in Ubuntu. They sit nicely in the /host/Python27/Lib/site-packages directory. But when I write a test python script and try to execute it, it gives me an ImportError whenever I try to import a module (for instance import numpy as np gives me ImportError: No module named numpy). When I type which python in the commandline I get the /usr/bin/python path. I think I might need to change things related to the python path, but I don't know how to do that.
You can use the following command in your terminal to see what folders are in your PYTHONPATH.
python -c "import sys, pprint; pprint.pprint(sys.path)"
I'm guessing /host/Python27/Lib/site-packages wont be in there (it doesn't sound like a normal python path. How did you install these packages?).
If you want to add folders to your PYTHONPATH then use the following:
export PYTHONPATH=$PYTHONPATH:/host/Python27/Lib/site-packages
Personally here are some recommendations for developing with Python:
Use virtualenv. It is a very powerful tool that creates sandboxed python environments so you can install modules and keep them separate from the main interpreter.
Use pip - When you've created a virtualenv, and activated it you can use pip install to install packages for you. e.g. pip install numpy will install numpy into your virtual environment and will be accessible from only this virtualenv. This means you can also install different versions for testing etc. Very powerful. I would recommend using pip to install your python packages over using ubuntu apt-get install as you are more likely to get the newer versions of modules (apt-get relies on someone packaging the latest versions of your python libraries and may not be available for as many libraries as pip).
When writing python scripts that you will make executable (chmod +x my_python_script.py) make sure you put #!/usr/bin/env python at the top as this will pick up the python interpreter in your virtual environment. If you don't (and put #!/usr/bin/python) then running ./my_python_script.py will always use the system python interpreter.
/host/Python27/Lib/site-packages is not a default python directory on linux installations as far as I am aware.
The normal python installation (and python packages) should be found under /usr/lib or /usr/lib64 depending on your processor architecture.
If you want to check where python is searching in addition to these directories you can use a terminal with the following command:
echo $PYTHONPATH
If the /host/Python27/Lib/site-packages path is not listed, attempt to use the following command and try it again:
export PYTHONPATH=$PYTHONPATH:host/Python27/Lib/site-packages
If this should work and you do not want to write this in a terminal every time you want to use these packages, simply put it into a file called .bashrc in your home folder (normally /home/<username>).
When installing other python libraries, specify the pip version you want to install it to, if it's python2 you use, then enter this syntax:
pip2 install <package>
For python3
pip3 install <package>