Difficulty running regetron in cmd - python

I want to follow the regex tutorial on http://regex.learncodethehardway.org/book/learn-regex-the-hard-waych1.html, but I am unsure how to execute regetron in cmd. I have followed the instructions to install it and the python interpreter does not give me an error when I type import regetron, so I know for certain it is installed.

Scripts usually get installed into the Scripts folder of your Python installation under Windows. Assuming you have Python 2.7 installed in the typical location, you should find a regetron executable in C:\Python27\Scripts.
FWIW, I typically put both C:\Python27 and C:\Python27\Scripts on my path under Windows for the above reason. Then commands introduced by packages are immediately available on the command line.
UPDATE: Regetron doesn't currently work for Windows. I've proposed a couple of patches to make it work. In the meantime, you can grab a new .zip from here and use pip to install it:
pip install .\regetron-1.4-windows.zip
UPDATE: My fixes have been incorporated into regetron. It should now work fine under Windows in a future version of regetron.

I used Cygwin to run regetron, and I did the following:
Install Cygwin, or update it if you already have it installed
Install Python when you pick your packages to install. Install wget,
too, because it'll make one of the steps below easier
wget http://python-distribute.org/distribute_setup.py
python distribute_setup.py
Use easy_install to install PIP. PIP is actively maintained, and supports package removal (unlike easy_install): easy_install pip
pip install regetron
Run regetron: regetron
Another word of caution: cmd.exe handles single-quoted (')and double-quoted strings (") differently than *nix shells. I've been burned when I've run Python scripts that take regex arguments (e.g. pywikipediabot) in cmd.exe. You can follow examples exactly, and the Wrong Thing will happen.
Cygwin doesn't have problems with ' and ".

Related

Should Which Pip and Which Python Return the Same Directory? Zeppelin Configuration On Unix RHEL

This is probably a really dumb question but I am stuck and wasting too much time on this so I would SO appreciate any help.
I am using a RHEL 7 box and installed Apache Zeppelin on it. Everything works except for the life of me I can't import Python packages such as Pandas.
I realized I didn't have PIP so I installed it with these steps: https://pip.pypa.io/en/stable/installing/ (notice I had to use the "--user" argument for the command "python get-pip.py").
Finally, I did "pip install pandas --user" which worked perfectly. I then go into my Zeppelin notebook and I cannot import pandas, even after restarting the Python interpreter.
I did some research and I think the problem is that "which python" and "which pip" are installed in different directories as the former results in "/usr/bin/python" while the latter in "~/.local/bin/pip".
So I suspect the packages installed with pip are basically getting loaded into a different version of python? If it helps, when I do "whereis python" I get 5 different results such as "/usr/bin/python" and "/usr/bin/python2.7" etc.
First thing to understand is: Python packages aren't installed globally, every installed Python has its own set of packages. BTW, pip being a Python package with a script is also not global. If you have a few different pythons you need different pips for them. I don't know Apache Zeppelin so I cannot guess if it uses the system Python (/usr/bin/python) or has its own Python; in the latter case you need to install pip specifically for Zeppelin so its pip install packages available for Zeppelin.
To investigate to what Python pip installs packages you need to find out under what python it runs. Start with shebang:
head -1 `which pip`
The command will prints something like ~/.local/bin/python. If it's not the version of Python you need to install packages for you need to install a different pip using that Python.
The most complex case would be if the shebang is PATH-dependent, something like #!/usr/bin/env python. In that case pip runs Python that you can find with which python.
PS. AFAIK the simplest way to install pip at RedHat is dnf install python-pip.
phd's answer was very helpful but I found that it was just a matter of using the root account to install the python packages. Then my Zeppelin was able to see any packages.

why are there multiple pip versions in my Python scripts folder?

I have a variety of different Python versions installed on my Windows system- a 2.7 version, a 3.5 version, and a 3.6 version (there are a bunch of different packages that only work with one version, or are too buggy in the 3.6 version, etc.).
Long story short, I'm trying to keep my all my pips and python.exes in order. I've added my C:/Python35 and C:/Python36 and their Scripts folders to my path, but I also want to make sure that I am using the right pip from my command line (for example, I don't want to pip install pyinstaller to the 3.6 version, since Python 3.6 doesn't play well with pyinstaller as of right now.
I see that inside my Python3x/Scripts/ folder, there are three different pips available: pip, pip3.5, and pip3.
So whenever I want to install a module for 3.5, I plan to issue the following command pip3.5 install package_name. Whenever I want to install something for 3.6, I'd use pip or pip3. Seems like a decent enough plan to me.
However, can anyone confirm if the three pips are all the same executable? If so, I'd like to delete pip and pip3 so that I don't accidentally confuse it with my Python 3.6 pip- is this acceptable practice or am I missing something? This SO post provides some insights but doesn't explain why there's multiple pips in the same folder. Also, why are three separate pips provided? Is it simply for convenience from the command line?
Within the same python installation all the different pip files you find should be the same executable, there is the multiple versions simply to help keep everything in order if there are multiple installs of python on a single computer.
I personally only have the main version of python I use for development set to my PATH variable on my windows laptop and then if I need to do anything to a different python I instead link directly to the necessary file with something like C:\Python36\Scripts\pip3 install natsort but that is simply personal preference and my way of organizing.
If you do have them all on path you can then simply call out pip3.6 install <package name> or whatever python version you are using
The difference between them is that each one install the package in its own folder, for example if i type pip install Django, it will be placed for python 2 version, but is a little bit complex when you have multiple version of python3 like you showed, the solution: Don't delete the files and makevirtualenv when you're working, that avoid problems.
This prevents dependency issues with different versions of Python. You also check out virtualenvwrapper which is a convenient way to manage your virtual environments
If you want to manage the version with virtualenv
virtualenv python2_project -p usr/bin/python2.7
virtualenv p35_project -p usr/bin/python3.5
virtualenv p3x_project -p usr/bin/python3.x

How to use easy install on Canopy Enthought?

I have installed the latest version of Enthought, I have the free express version. and I want to install the pyodbc package.
I have gathered that I need to use easy_install to install pip to install pyodbc.
However, I have no luck in using easy_install or even enpkg.
If I open enthought editor and type in:
enpkg pip
or
easy_install pip
all I am getting in return is syntax errors.
(I am very inexperienced with using external packaged that are not already installed into Enthought.)
What exactly are the syntax errors? I am guessing you are typing this into the python shell shown by the enthought editor?
What you need to do is open up a command shell. Are you on Windows? Try running cmd.exe - Canopy might even provide a special shell to use (with paths all set up for you) so check the start menu.
Then, you should be able to use easy_install and enpkg. You should see a prompt similar to:
C:\Users\Sameer\>
Type it at that prompt.
The python prompt looks like this:
>>>
You can't run enpkg or easy_install from there. Well... technically you can by shelling out, but first, try the above.

How do you install PyCallGraph / use pip?

and thanks to anyone who gives some of their time to consider my problem.
What I need help on is for someone to give me a simple and accessible explanation on how to install that module. I have never, ever used anything from PyPi before, I have only heard of pip after looking up PyCallGraph.
I'm not a programmer first, I'm doing an accounting internship and am using python to write scripts to help me speed up some processes, at the urging of a colleague who himself uses python. I write scripts using Notepad++ and execute them through IDLE.
I'm currently working on optimizing a script I wrote and came upon PyCallGraph while checking this very site on tips on how to do so.
I tried the very minimalistic instruction of just doing "pip install pycallgraph" just about anywhere I could think of, including cmd.exe, to no avail. Runing get-pip.py directly seems to have worked for installing pip, though.
Otherwise I can always just stick with the cProfile printout and write-off using modules needing such an install, although that saddly seems to be quite a few...
Step 1: Install PIP
Open terminal (cmd.exe, PowerShell, whatever)
Download get-pip.py and place it in the working directory of your terminal
Install PIP by invoking python get-pip.py
Confirm that PIP was installed correctly by invoking command pip (should display help if success)
If pip didn't work, make sure your PATH environment variable has been set up correctly. In typical Windows installations pip is installed under c:\Python27\Scripts. Make sure this folder is included in PATH.
Step 2: Install your library with PIP
Invoke pip install pycallgraph
PIP installs the library and it can be now used from Python

Installing a package to Canopy

I'm really new to coding, programming, Python, and just computers in general, so I need some help with Canopy. I've been having pretty consistent troubles installing any packages to Canopy; some stuff is in the internal package manager,but whenever it isn't, it's really confusing. I guess I'll list a specific installation.
I'm trying to install "pywcs" (link provided below) to my Win7 64-bit machine. I have Cygwin if that helps at all. I do not know how to go about this; the stuff I found online is pretty confusing, and Cygwin easy_install (filename) never seems to work. Any step-by-step solutions?
The way I installed astropy is as follows.
Open Windows Terminal
Change Directory to C:\Users\<USER NAME>\AppData\Local\Enthought\Canopy32\User\Scripts
Type easy_install.exe astropy
Wait until the download completes, and restart Enthought.
sometimes installing packages can be hard for enthought canopy . You could install all python packages using pip install mrjob command on the its own canopy command prompt
Go to tools tab on the canopy editor ,
Left click on the canopy command prompt ,
Finally pip install <package name> and hit Enter key
The key point is that in order to install a package into any Python distribution (including Canopy Python), you should use that Python to perform the installation. You refer to Cygwin's "easy_install", but you should instead use Canopy's easy_install.
As described in this article, the easiest way to be sure that you are running Canopy's Python (and Canopy's easy_install) is to have Canopy Python on your PATH. This is done by default during Canopy installation, but if you uncheck this option then, or if your Cygwin installation doesn't use your Windows PATH, then you will need to adjust your Cygwin PATH accordingly.
Doing as Sukrit suggests, and running the installation from the Canopy Python Scripts directory, is also a reasonable approach.
Alternatively, depending on its compiler dependencies, you may be able to install astropy from a Windows Command Prompt rather than from Cygwin (of course Canopy must be on the PATH here too, as it would be by default.)
In Linux you can do it as follows.
1) Make sure you are using the Canopy version of Python - check out https://support.enthought.com/entries/23389761-Installing-packages-into-Canopy-User-Python-from-the-command-line
2) At the command prompt use easy_install, for example:
$ easy_install pp==1.5.7
to install version 1.5.7 of pp
Just for information, Astropy is now included by default in Enthought Canopy:
https://www.enthought.com/products/canopy/package-index/

Categories

Resources