Nosetests execution with different Python versions? - linux

I'm having trouble with Python 2.7 & 3.5. Right now I use GIT to acquire repositories and their python folders all have 2.7 syntax.
The problem: When i'm attempting to Automate using repositories, my .local/bin nosetests first line of code shows:
#!/usr/bin/python3
so, it checks for
.local/lib/Python3.5/site-packages/nose
Nowhere to be found is a Python 2.7 folder with similar directories to Python 3.5.
So I will always get a syntax error, as its checking my repositories Python coding, and since they are not Python3 syntax, it will give me errors. I checked using command
python -v
python3 -V
and indeed have 2.7 and 3.5 installed.
So I just need guidance/help on how to just gain Python 2.7 site packages with nosetests, so I can automate correctly using the same version as the repositories python. If I left out anything, I will try my best to fill in the gaps/add more details. I will of course troubleshoot.

Nowhere to be found is a Python 2.7 folder with similar directories to Python 3.5.
First, uninstall nosetests for python 3 with pip3 uninstall nose.
Then install nosetests for 2.7 with pip2.7 install nose.
After you do this, the default nosetests should be for python 2.7.
You may want to look into the default python for your project to python2.7 by using virtualenv.

Related

Installing Python 2.7 projects in a system with Python 3.10

I've come to a delicate situation:
My company's projects are all based in Python 2.7 and use specific PATH and PYTHONPATH exports to get around each other. The new machine I received has Ubuntu 22.04 and Python 3.10 preinstalled. My previous used to have Python 2.7 and I just installed 3.x on top and it worked just fine, at the beginning. I ended up messing up all the version altogether and everything seemed broken. So now I'm cautious on how to proceed
I've watched numerous tutorials online about setting up a virtual environment and how 'easy' it is to work with multiple version but seems that don't do the trick.
I would like to set up a virtual environment in Python 2.7 where I can just
python setup.py install ....
with all my packages and install them using python 2.7
At the same time, I'd like Python 3 to be available (because I'm futurizing some of these projects) to also install them using Python 3:
python3 setup.py install ...
What is the best strategy to implement this on my machine? Python 2 looks like it's not installed at all. Should I just install it on top of 3.10 ?

Run scrapyd in Python 3.6

I've been looking around and I can't seem to find an answer on how to run scrapyd in Python 3 and above. When I run it it keeps defaulting to python 2.7, though I recall reading in the docs or elsewhere that scrapyd supports python3:
https://scrapyd.readthedocs.io/en/stable/news.html#id1
Running on an AWS Ubuntu 18.04 server. What am I doing wrong? How can I change to Python 3.4 and above?
I'm having problems because I'm using abstract inheritance in my spiders which python 2.7 doesn't support.
Edit: I'm able to run Scrapyd in Python 3 using a virtual environment, but how would you do it without one?
Simplest solution is use a virtual enviroment.
Since you are using Ubuntu and you can make it work using a venv I assume you installed scrapy using pip instead of pip3. Since Py2.7 is the stardard reference to python in Ubuntu, when running pip it will execute pip for py2 instead of py3.
Another way would be uninstalling pip uninstall scrapy and installing it again using pip3 pip3 install scrapy. This should fix the reference to scrapy. If by any chance you also use scrapy in py2.7 and therefore can't uninstall, then you have another reason to use venv.

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.

Using latest Python version

I am setting up a new computer and the current latest version of Python is Python 3.4.6. I am trying to update it to version 3.7.0 (the latest version at the time of writing).
I tried pyenv install 3.7.0 and it successfully installed.
But when I type $ python3 --version at the command line it still says Python 3.4.6.
When I type $ which python3 the path it shows is /.pyenv/shims/python3.
Navigating to that path I find that there also exists /.pyenv/shims/python3.7.
How do I point the python command to the newest install?
I know there are a million questions asking how to point python from Python 2.x to Python 3.x. But I have not found one showing how to point from Python 3.old to Python 3.new
I am using Linux OpenSuse.
Use the pyenv global command. In this case, it should be pyenv global 3.7.0. Check out the pyenv commands list for more info.

Does TensorFlow 1.9 support Python 3.7

I'm hesitating whether to downgrade to Python 3.6 or install a new version of TensorFlow.
Does TensorFlow 1.9 support Python 3.7?
I was able to install Tensorflow 1.12.0 with Python 3.7 on MacOS, with the following command.
sudo python3 -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.12.0-py3-none-any.whl
Not yet. It seems there are some variables named "async", which has become a keyword in 3.7. Shouldn't be too difficult to fix, but still a problem.
Source: https://github.com/tensorflow/tensorflow/issues/20444
Probably not yet.
First of all, you will probably get a SyntaxError: invalid syntax because some parameters and variables at the pywrap_tensorflow_internal.py module have the name async which is a reserved keyword in Python 3.7.0 (see also this post).
However, you can solve this by simply changing the name of all these (Ctrl + R and Replace All) from async to for example async1.
The problem is that then you will probably get a ImportError: No module named '_pywrap_tensorflow_internal' which perhaps may be fixed for any previous version before Python 3.7.0 as this post on StackOverflow suggests but personally I could not fix it on my laptop with Python 3.7.0 .
Consequently, I simply downgraded to Python 3.6.6 and now Tensorflow is working fine.
There is a whl built here. However in my run it was cpu version.
https://www.lfd.uci.edu/~gohlke/pythonlibs/
as of Aug 26tH, there is an update on the tensorflow github site
https://github.com/tensorflow/tensorflow/pull/21202
Tensorflow 1.13.1 now supports Python 3.7.
According to the comments on github
see
https://github.com/tensorflow/tensorflow/issues/20517#issuecomment-457185528
by member av8ramit
"We are aiming to try and have Windows and Ubuntu python binaries by rc2 or the official."
the estimated release date for 2019-02-03
however on
https://github.com/winpython/winpython/issues/687
one can read from a winpython contributor:
"Tensorflow-2 is 2019, Tensorflow-1 on Python-3.7 is still not in sight"
Finally Worked for me!
On Python 3.6.4 (even 3.6.5 failed for me)
Install Python3.6.4 from here:
https://www.python.org/downloads/mac-osx/
If you're facing issues with Python pkgs that you already had on you older version just revert it using this post:
python location on mac osx
I found this to work after searching for a while.
As Tensorflow only supports Python 3.6 as of now, you can install a different version of python alongside your standard one. Here are the steps I followed:
Download the Python3.6 tgz file from the official website (eg. Python-3.6.6.tgz)
Unpack it with tar -xvzf Python-3.6.6.tgz
cd Python-3.6.6
run ./configure
run make altinstall to install it (install vs altinstall explanation here Difference in details between "make install" and "make altinstall")
You'll normally find your new python install under /usr/local/bin. Now you can create a new virtualenv specifying the python version with:
virtualenv --python=python3.6 env3.6
Get into the virtualenv running the command source env3.6/source/bin/activate.
Install tensorflow with the classic pip install tensorflow
Profit
First of all,
*conda create -n yourenvname python=3.6
*conda activate yourenvname
*pip install tensorflow
then it will work like rock.

Resources