What’s the difference between python and python3 - python-3.x

I’m following some instructions to configure my pc to coding some solidity sample projects and the instructions tell me to install pip and pipx, but first I need to check the version of Python installed. The instructions say to run this at the command prompt:
python3 --version
but when I do, I get the following error:
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
However, if I run:
Python --version
It returns: Python 3.8.5
So when I’m instructed to run “python3” …. Is that an apple syntax where I would use just “python” for windows? I’ve googled this and could not find any clarification.
Thank you.

Often in reading instructions for installing things in Python, we see syntax like this:
python3 --version
but on my PC I get an error "Cannot find python3" even though I have python 3.7, 3.8 and 3.9 installed.
For me using this syntax worked:
python --version
python -m pip install --user pipx
python -m pipx ensurepath

Related

"No module name adafruit_servokit"

I am working on Jetson Nano and trying to control servo motors. I am using PCA9685. I have installed all the pre-requisites for that
sudo pip3 install adafruit-circuitpython-servokit
Faced an error called
SyntaxError: future feature annotations is not defined
i updated python for that and the issue was resolved. Now the issue is that when i use python 3.8 as an interpreter in Visual studio i face the error
No module name adafruit_servokit
But when i use the python 3.6, the adafruit_servokit error is solved and the annotation error arises.
Looking forward to every suggestion. Thank you
This is because you have conflicting interpreters for your python installation.
Inside your Visual Studio terminal, try using:
python3.8 -m pip install adafruit-circuitpython-servokit
Using python -m pip install instead of just pip install is recommended. The reason is that it will use the correct interpreter for your python installation, specially if you have many versions installed. More details here: https://snarky.ca/why-you-should-use-python-m-pip/
---EDIT---
You should replace python3.8 with your target version number.

How can I move from the default pre-installed Python 2.7 on my Mac to accessing Python 3.7 from Anaconda in Terminal?

I may be leaving out many details, but I'll attempt to construct the best picture of what is happening here.
My Mac is running OS Catalina 10.15.6, I got it back in April, and it has Python 2.7 in
I'm learning to use pip install and PyPI from terminal, and the first oddity I noticed was that I had to install pip. I shouldn't have, because it comes with Anaconda Navigator. So I did sudo easy-install pip and it installed. Then I did pip install requests which worked fine, then pip install colorama and then it threw this error message:
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: colorama in ./Library/Python/2.7/lib/python/site-packages (0.4.3)
My desire is to be able to use the Anaconda Python from terminal, since this 2.7 Python is dying and I need to be able to do so for my upcoming bootcamp and current Python course. I tried many conda commands to create an environment, see my current environment, etc, and they all failed because my terminal doesn't recognize conda as a command. I see this:
ryanlindsey#Ryans-MacBook-Pro ~ % conda info --envs
zsh: command not found: conda
ryanlindsey#Ryans-MacBook-Pro ~ % conda create -n myenv python=3.6
zsh: command not found: conda
ryanlindsey#Ryans-MacBook-Pro ~ % conda
zsh: command not found: conda
I've read stack overflow suggestions to add it to my path, but even when I use the code it seems to do nothing.
If this is useful, here is my PATH when I do echo $PATH
/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
My shell I am using is zsh.
Anyone experienced in solving problems like this?
MacOS comes with python 2.7 installed by default. You can't move or remove it. Catalina also comes with python 3.7 (though it requires the download of Xcode command line tools when first run to complete it.)
Usually, python 3 versions are instigated with the command python3. Similarly, pip3 manages libraries for python 3, while pip manages libraries for python 2.
It doesn't look like you've actually installed Anaconda. Anaconda is a third-party product, which does not come bundled with the OS. You'll need to install that and follow the instructions on their website.
https://docs.anaconda.com/anaconda/install/

autopep8 not found in cygwin

If I try to use autopep8 in cygwin (64bit, WIndows10) i get the message "command not found".
$ autopep8
-bash: autopep8: command not found
I tried pip install autopep8 but pip is also not found, only pip2 and pip3.
If I use python -m pip install autopep8 it works so I can call
python -m autopep8
but I want to run a script where just autopep8 is called:
if ! type -p autopep8 >/dev/null; then
echo "autopep8 not found" >&2
autopep8() {
Any ideas how to solve this?
First, you must install PyPi packages to the correct Python installation, and second, you must install the same package to every Python installation in which you want to use it.
Now, a special note about installing Python on Cygwin. You have a choice of several Python versions to install, and scores of packages for use with each of those versions. Avoid Python version 2 unless you have a clearly define reason, as it is post End-of-Life. Instead, install one of the versions of Python 3. As of today, version 3.6 and 3.7 have the more complete sets of optional packages. Version 3.8 beta 4 is available.
For a my install of Python 3.8, I used the Cygwin setup app to install these packages: Python38 (Py3K language interpreter), Python38-pip (Python package installation tool), Python38-setuptools (Python package management tool), Python38-virtualenv (Creates isolated Python environments), and Python38-wheel (Python package format module). To write X11 GUI apps, add Python38-tkinter (Py3K Tkinter GUI module). To install binary packages, add Python38-devel (Py3K language interpreter).
You will be able to install pure Python packages from PyPI. To install binary packages you will also need to have the GNU compiler tool chain installed, and you will need to handle dependencies with other Cygwin packages on your own.
The Python 3.6 and 3.7 installations have addition packages which, in many cases, contain binary packages with the above mentioned dependencies already resolved, or have some useful customizations for the Cygwin environment.
Cygwin has both Python 2 and Python 3. As of today, after installation, you execute Python 2 by python and Python 3 by python3. Be careful which Python you execute as you may get a windows version of Python, if installed, and in your path. which python will always tell where the executable lives, and python -V, etc., will tell you which version you are running. Generally, you want to run a Cygwin version of Python from the bash prompt and Windows versions of Python only from the command prompt or windows GUI.
The safest way to use pip is to use the module version for the Python executable you have chosen, i.e., python -m pip, etc. This avoids having to also remember to use pip with Python and pip3 with Python3.

Cannot install python3.6 on Debian 4.9 VM

I'm running a Debian VM (4.9.189-3+deb9u1) on the Google cloud. I want to run a script on this instance; the script works fine on my local machine (Mac OSX Mojave 10.14.6; python 3.6.8). However, when I run it on the VM I get an error that seems to relate to the fact that my the VM runs python 3.4 when the script needs python 3.6+.
Here's the problem. When I run python -V, the response is Python 3.7.4. However, when I try to install the library supporting the script I want to run
pip3 install --user --upgrade -e
git+https://github.com/twintproject/twint.git#origin/master#egg=twint
I get
twint requires Python '>=3.6.0' but the running Python is 3.5.3.
I have tried changing the default python as detailed here; this doesn't seem to work––in fact, python 3.6 isn't even visible as an option when I query ls /usr/bin/python*. Can anyone offer some advice on how to proceed here? Thanks.
It seems like you have multiple Python versions available. If python -V gives you Python 3.7.4, you can use:
$ python -m pip install --user --upgrade -e git+https://github.com/twintproject/twint.git#origin/master#egg=twint
to invoke pip from that same Python interpreter.

Why virtualenv shows all packages installed and do not install modules in virtualenv?

Question
I am not sure why when virtualenv active, pip freeze stills showing all modules when it suppose NOT to. What am I doing wrong?
On the terminal
I tried two ways to create a virtual env:
virtualenv my-virtualenv
virtualenv --no-site-packages my-virtualenv
then activate it
source my-virtualenv/bin/activate
Results
Both show all packages (when they suppose not to). Running command pip freeze I get:
(my-virtualenv)$ pip freeze
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
actionlib==1.11.9
angles==1.9.11
bondpy==1.7.19
camera-calibration==1.12.20
camera-calibration-parsers==1.11.12
catkin==0.7.6
cv-bridge==1.12.4
diagnostic-analysis==1.9.2
diagnostic-common-diagnostics==1.9.2
diagnostic-updater==1.9.2
dynamic-reconfigure==1.5.48
gazebo-plugins==2.5.13
gazebo-ros==2.5.13
...
rosnode==1.12.7
rosparam==1.12.7
rospy==1.12.7
rosservice==1.12.7
rostest==1.12.7
rostopic==1.12.7
rosunit==1.13.5
roswtf==1.12.7
tf2-ros==0.5.16
topic-tools==1.12.7
xacro==1.11.2
Running
(my-virtualenv)$ which python
/home/user/.../my-virtualenv/bin/python
(my-virtualenv)$ python -V
Python 2.7.12
and
(my-virtualenv)$ which python3
/usr/bin/python3
(my-virtualenv)$ python3 -V
Python 3.5.2
Hence, I even can use python3 when virtualenv is activated but it uses the pc installed module. Moreover, new installed packages are install in the pc and not the virtualenv and I can't install python3 in the vitualenv because it "exists" already (but in the pc).
I was having the same issue and it was because, somehow, Python configuration of ROS was generating it.
I solved it removing the source commands of ROS from the ~/.bashrc. E.g.:
source /opt/ros/melodic/setup.bash
source $HOME/ROS/aslam_ws/devel/setup.bash
By the way, I realised that, before changing anything, creating the environment from PyCharm works properly too (when in the terminal I still had the issue).
There must be a better solution but I haven't found it yet.

Resources