How to use/install python 2to3? - python

From this https://docs.python.org/3.4/library/2to3.html it says that 2to3 should be installed as a script alongside the python interpreter. However, in my /usr/bin/ folder there are no 2to3 executable, and running find from / finds no 2to3 executable either. I do however have a folder called lib2to3 at /usr/lib64/python{3.4/2.7}/lib2to3 but containing nothing I found relevant. In python/site-packages/setuptools/ there is a lib2to3_ex.py script, but nothing happens if I run it. How do I get to the point where I can simply type 2to3 upgradethisscripttopython3.py ?

You need to first install the following packages:
apt install 2to3
apt install python3-lib2to3
apt install python3-toolz
For windows just install 2to3
pip install 2to3
Then, You can simply go to that directory your python file is in and type the following command:
2to3 ./filename.py
OR for writing the updated python 3 code to the existing file
2to3 . -w
This last will convert all the python files that are in the directory.

So the solution is that at least not for me, the Tools/scripts files were not automatically installed. On ubuntu this would be solved by installing python-examples which on opensuse is called python-demo

On CentOS (and other RHEL-like distros) you will need to run yum install python-tools, which installs 2to3 to /usr/bin/2to3

On Fedora 29, the python-tools is not providing 2to3. I had to install the development package:
dnf install python3-devel
I found this out by first calling:
dnf whatprovides /usr/bin/2to3

So far I've been using pip install 2to3. Conversions worked like absolute charm!
(I'm on Ubuntu 18.04)

Check if you have the file /usr/bin/2to3-2.7 (or similar). If one exists, then simply create a symbolic link to it with a link name of 2to3 (e.g.: ln -s 2to3-2.7 /usr/bin/2to3).

Related

How to install Python packages from python3-apt in PyCharm on Windows?

I'm on Windows and want to use the Python package apt_pkg in PyCharm.
On Linux I get the package by doing sudo apt-get install python3-apt but how to install apt_pkg on Windows?
There is no such package on PyPI.
There is no way to run apt-get in Windows; the package format and the supporting infrastructure is very explicitly Debian-specific.
Not quite what you're looking for, but it's possible to use apt-offline on Windows to download the packages. However, you still need a Linux box to generate the sig file.
For example:
python apt-offline set vim-offline.sig --install-packages vim
Will not work:
ERROR: This argument is supported only on Unix like systems with apt installed
However, if you run that command on Linux first, the following command should work on Windows:
python apt-offline get vim-offline.sig -d vim
apt-offline source is available here:
https://github.com/rickysarraf/apt-offline
To build it, simply run:
python setup.py build
python setup.py install
I got it to run with Python 3.8.2 on Windows 10.
Note: in the end of the day, you're just downloading a .deb package and it is simply an ar file containing a tarball and can be extracted with tools like 7-zip. However, if it contains a Linux binary (vim example), there isn't much you can do with it on Windows.
One can use chocolatey the equivalent for windows.
https://chocolatey.org/install
add it to the windows PATH environment
C:\ProgramData\chocolatey\bin
Restart python or anaconda. And is ready to use.
To install packages inside a .py script or a Jupiter notebook, use the syntax below
!choco install [package name]

How to properly install python3 on Centos 7

I'm running Centos7 and it comes with Python2. I installed python3, however when I install modules with pip, python3 doesn't use them. I can run python3 by typing python3 at the CLI
python (2.x) is located in /usr/bin/python
python3 is located in /usr/local/bin/python3
I tried creating a link to python3 in /usr/bin/ as "python", but as expected, it didnt resolve anything. I renamed the current python to python2.bak It actually broke some command line functionality (tab to complete). I had to undo those changes to resolve.
Suggestions welcome. Thanks.
The IUS project has ready to go RPM packages of python34u-pip, python35u-pip, and python36u-pip. These will give you corresponding pip3.4, pip3.5, and pip3.6 commands. As expected, the packages installed by those will be available to the corresponding python3.4, python3.5, and python3.6 interpreters.
Do you have pip for python3, too? Try pip3 rather than pip. I assume your regular pip is just installing the modules for Python 2.x.

How to use pip with multiple instances of python

I recently installed python3 only to realize that mysql-python as well as many other modules were not well supported with it yet. So I changed the path in my bashrc file to point to an installation of python 2.7. The problem is that when I installed python 3 I also installed distribute and pip along with it. I removed the pip and distribute files from the python3 bin directory and installed setuptools and pip using python 2.7 however now when I use the pip command to install django and mysql-python, I get a bash error python331/bin/pip No such file or directory. It's still looking for pip in the python3 install. How can I remedy this?
Thanks
...I get a bash error python331/bin/pip No such file or directory.
It's still looking for pip in the python3 install. How can I remedy
this?
bash, by default, hashes the locations of commands to avoid searching $PATH each time, so if, when you execute...
$ type pip
...you get something like...
pip is hashed (python331/bin/pip)
...you just need to clear the hash table for bash with...
$ hash -r
...then it'll pick up the version in Python 2.7 the next time you try to run pip.
Fixed it.
Renamed the directory of where the python3 was installed, bash automatically looks for the next available python install python 2.7

pip on Windows giving the error - Unknown or unsupported command 'install'

I installed pip on Windows by downloading http://pypi.python.org/packages/source/p/pip/pip-1.0.2.tar.gz#md5=47ec6ff3f6d962696fe08d4c8264ad49 and running python setup.py install
Installation went fine with no errors.
But when I tried installing selenium package with it, it gives me the following error -
pip install -U selenium
Unknown option: u
Unknown or unsupported command 'install'
Where I'm making the mistake?
Do you happen to have the Perl pip lying around somewhere?
Sounds like the problem described here:
https://github.com/mike-perdide/gitbuster/issues/62
To check, in Windows command prompt execute:
C:\>where pip
This will potentially output the following:
C:\strawberry\perl\bin\pip
C:\strawberry\perl\bin\pip.bat
If so, this is your problem. Unistall Strawberry Perl or use the full path to python pip.
This error is because the system is finding pip.bat before it finds pip.exe.
You do NOT need to uninstall Strawberry Perl or type the whole path.
What I do is to simply type pip.exe (same number of keystrokes as apt-get) when I want to use the Python utility. This method seems to work find for me on Win7 with Python(x,y) 2.7x and Strawberry Perl installed.
Had the same problem under Ubuntu and did:
$ sudo apt-get remove pip
$ sudo apt-get install python-pip
I had this problem as well, and like Johannes said, it's because the perl pip is interfering with your Python pip.
To get around it, you can simply do this as well:
python -m pip install <package_name>
In addition to the very helpful nswer of Johannes:
If you don't want to uninstalll Strawberry, you can re-arrange the order of PATH entrys in your Windows system to ensure your Python\Scripts are found before the strawberry entries. If you don't want to do this manually, you can use tools like the "Rapid Environment Editor".
You should provide path in environment variable for pip.exe file
while executing install command you should use below command
pip.exe install selenium
This will surely work, for me this worked :)
You can also solve this problem without removing Strawberry Perl or type the whole path.Move to this C:\Python2.7\Scripts(your Python directory) directory,then use pip command.
For Python 3.X and above:
In the CMD prompt type:
py -m pip install <package_name>
Make sure pip is installed already.
Setup the environment variable for pip pointing to the exe file
To upgrade:
py -m pip install --upgrade pip
Same issue with DwimPerl. Uninstalling Dwim fixed the issue as well.
C:\Python27\Scripts\pip.exe install -U selenium
I have the same problem in windows 10, finally resolved the problem successfully.
I used the following command
where pip
I was showing multiple installations of pip. Once removed other installation it worked fine.
open cmd and type where pip and you will have
C:\Dwimperl\perl\bin\pip.bat
C:\Dwimperl\perl\bin
C:\Users\athus\AppData\Local\Programs\Python\Python38-32\Scripts\pip.exe
and go to C:\Dwimperl\perl and delete bin folder.
and again type where pip and you will only have
C:\Users\athus\AppData\Local\Programs\Python\Python38-32\Scripts\pip.exe
and enjoy python pip.

How to properly install Python on OSX for use with OpenCV?

I spent the past couple of days trying to get opencv to work with my Python 2.7 install. I kept getting an error saying that opencv module was not found whenever I try "import cv".
I then decided to try installing opencv using Macports, but that didn't work.
Next, I tried Homebrew, but that didn't work either.
Eventually, I discovered I should modify the PYTHONPATH as such:
export PYTHONPATH="/usr/local/lib/python2.6/site-packages/:$PYTHONPATH"
My problem is that I didn't find /usr/local/lib/python2.*...etc
The folder simply doesn't exist
So my question is this:
How do I properly install Python on OS X Snow Leopard for it to work with opencv?
Thanks a lot,
I spent a couple days on this myself. For me, the problem was that that OpenCV installer was not finding the right python installation. It was defaulting to the MacOS-installed version despite the fact that I had upgraded python with homebrew and was using a virtualenv for python. I have collected most of my setup in a gist here:
https://gist.github.com/4150916
Use homebrew to get all the dependencies, but then download the OpenCV tarball and compile yourself being sure to specify all the python related configuration options.
Assuming a virtualenv named 'opencv'...
cd OpenCV-2.4.3/
mkdir release
cd release
cmake -D PYTHON_EXECUTABLE=$WORKON_HOME/opencv/bin/python \
-D PYTHON_PACKAGES_PATH=$WORKON_HOME/opencv/lib/python2.7/site-packages \
-D INSTALL_PYTHON_EXAMPLES=ON\
-D PYTHON_INCLUDE_DIR=/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Headers\
-D PYTHON_LIBRARY=/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib\
..
make -j8
make install
You need to install the module using your python2.7 installation. Pointing your PYTHONPATH at stuff installed under 2.6 to run under 2.7 is a Bad Idea.
Depending on how you want to install it, do something like python2.7 setup.py or easy_install-2.7 opencv to install.
fwiw, on OS X the modules are usually installed under /System/Library/Frameworks/Python.framework/ but you should almost never need to know where anything installed in your site packages is physically located; if Python can't find them without help you've installed them wrong.
Installing OpenCV with Homebrew
brew tap homebrew/homebrew-science
brew install opencv
Setting up Python
Depending on your install location - OS X Default
cd /Library/Python/2.7/site-packages/
or - Homebrew Python
cd /usr/local/lib/python2.7
Then create the symbolic link
ln -s /usr/local/Cellar/opencv/2.4.9/lib/python2.7/site-packages/cv.py cv.py
ln -s /usr/local/Cellar/opencv/2.4.9/lib/python2.7/site-packages/cv2.so cv2.so
The above method sourced from a blog post.
I searched and tried installing opencv3 with python3 for 3 days. Some links suggest for Brew and some virtual env, some say install xcode but all failed in my case.
Dont use linux steps to instal opencv-python on Mac. Problem with Mac is Python 2.7 is already installed by Mac. On top of that installing and linking all site-packages is little problematic and we end up with errors.
I'll share what I did: easy steps to install complete package opencv3, numpy, matplotlib, notebook, spyder etc.. on Mac.
Install anaconda, it creates a directory and install everything inside that
use this link -> https://www.continuum.io/downloads
download command-line-install
After download, goto terminal and download location of anaconda.
$ bash Anaconda3-4.3.0-MacOSX-x86_64.sh
Installation will ask you to append path to .bash_profile >> say yes
Goto home directory, run .bash_profile
$ source .bash_profile
check python, should be pointing to
$ which python
$ /.../anaconda/bin/python
Last step
$ pip install opencv-pyhton
$ python
$ import cv2
if no errors, we are good to go.

Categories

Resources