./configure doesn't work on python 3.8.2 on windows - python

I am trying to execute the code:
./configure \
--prefix "$(dirname $(pwd))" \
--with-openssl=$(openssl version -d | sed -r 's/OPENSSLDIR: "([^"]*)"/\1/') \
&& make && make install
popd
this error is recived:
File "<ipython-input-7-f69304efaff4>", line 1
./configure
^
SyntaxError: invalid syntax
Does anyone know how to fix it?

This code should be executed in bash shell, not python

It should be executed in bash shell but as i am using windows it was not possible.
In this code i was trying to install FreeTDS and after download the stable realease and the binaries for windows I was able to install it by using the windows powershell to run the .ps1 file

Related

How can I run a python command for the correct name (py, python, python3)

I think this is related to: How can I check if a program exists from a Bash script?
Specifically, I want to run py -m http.server on computers that have py but don't have python3 and I want to run python3 -m http.server on computers that have python3 but not py. I also tried just checking the version number: py -v && py -m http.server; python3 -v && python3 -m http.server but this still seems to have the same problem, and hitting ctrl+C twenty times doesn't kill it.
I tried py && py -m http.server; python3 && python3 -m http.server but I believe it's executing the second command within python. Also, there are other aliases for Python on other computers. I know that I could just set py as an alias for python3, but I'm looking for a universal solution.
(Side note: It really bothers me that this is inconsistent. They should all just work.)
Eventually, I want a script that runs two things in parallel: the first is just npm run dev which has a --watch on it and has to continue to run, and the other is to cd docs/ then use python to host on localhost, then open chrome to localhost:8000, additional help would be much appreciated, still a beginner to Linux.
I also want to make a second command that runs npm run build, changes the second line in docs/sw.js from const dynamicCacheName = 'site-dynamic-vNUMBER'; to replace NUMBER with NUMBER+1.
Does this do what you're after? Assuming bash or similar:
( py -V && py -m http.server ) || ( python3 -V && python3 -m http.server )
On my box this does the following:
$ ( py -V && py -m http.server ) || ( python3 -V && python3 -m http.server )
py: command not found
Python 3.5.2
Serving HTTP on 0.0.0.0 port 8000 ...
For the second part of your question you could have a small bash script like this (I included the python or py check):
#!/bin/bash
npm run dev --watch &
chromium-browser "http://localhost:8000" 2>/dev/null &
cd docs/ || exit # Exit if the cd command fails
if command -v py -V &> /dev/null; then
echo "py"
py -m http.server
elif command -v python3 -V &> /dev/null; then
echo "python3"
python3 -m http.server
else
echo "Neither command found"
fi
& At the end of a command will run it in the background, as written above it will still display the output of the commands.
If you kill the script with CTRL+C it will kill everything, chromium, the python server and the npm run.
I actually wanted to post a full answer since I got what I was after from several answers and comments and chatting with a friend:
I installed the npm package concurrently and then added a local-dev npm script in my package.json:
"scripts": {
"dev-no-watch": "postcss src/styles.css -o docs/css/styles.css",
"dev": "postcss src/styles.css -o docs/css/styles.css --watch --verbose",
"build": "cross-env NODE_ENV=production postcss src/styles.css -o docs/css/styles.css && cleancss -o docs/css/styles.css docs/css/styles.css",
"localhost": "cd docs && ( py -V && py -m http.server ) || ( python3 -V && python3 -m http.server )",
"local-dev": "concurrently --kill-others \"npm run dev\" \"npm run localhost\""
},
Which runs both concurrently, and upon hitting ctrl+C, kills both as well.
I of course added localhost from the answer for the original question of detecting python version and running it correctly/failing gracefully, etc, and that works like a charm.
Hope this answer is helpful to someone in the future : )
(Now I just need to find out hos to edit a line of a file from the command line OS independently)

How can I correctly install & run pip in a wine-emulated python version (inside a docker container)?

I wanted to do a MetaTrader5 environment with Python. While I could do it in my Windows machine, I'd like to have it as a standalone Docker container to, say, deploy in my (I have two other systems that I prefer for coding: mac and linux) machine or perhaps an AWS ECR.
For that purpose, I created this docker file:
FROM ubuntu:20.04
# In order to use the python version, we'll have to install
# wine emulator. We're installing both 32 and 64 bits API.
RUN dpkg --add-architecture i386
RUN apt update
ENV TZ=UTC
RUN apt-get install --assume-yes apt-utils
RUN DEBIAN_FRONTEND=noninteractive apt-get install --assume-yes tzdata
RUN apt-get install --assume-yes wine64 wine32
# The root wine prefix will be: /root/.wine.
# Now MetaTrader5 is being moved to the Program Files directory.
COPY ["MetaTrader5", "/root/.wine/drive_c/Program Files/MetaTrader5"]
# Also the Python interpreter is moved to that directory.
ADD ["python-3.9.0", "/root/.wine/drive_c/Program Files/python-3.9.0"]
# And the get-pip script is added to the standard interpreter.
ADD ["https://bootstrap.pypa.io/get-pip.py", "/root/.wine/drive_c/Program Files/python-3.9.0/get-pip.py"]
# The server script itself is then added as another application.
RUN ["mkdir", "-p", "/root/.wine/drive_c/Program Files/MetaTrader5 AI Server"]
COPY ["server.py", "/root/.wine/drive_c/Program Files/MetaTrader5 AI Server/server.py"]
############### 'Till this point, everything is fine.
# Now, pip will be installed for windows.
RUN ["wine", "/root/.wine/drive_c/Program Files/python-3.9.0/pythonw.exe", "/root/.wine/drive_c/Program Files/python-3.9.0/get-pip.py"]
# And then, metatrader will be installed, along with aiohttp
# library for websockets.
# RUN pip install MetaTrader5 aiohttp
# Choosing this tail command is just for debug
# purposes, as the true implementation will use
# the server.py file as entry point.
CMD ["tail", "-f", "/dev/null"]
The issue I'm having involves the last part: When get-pip.py is executed, the Scripts/ directory (/root/.wine/drive_c/Program Files/python-3.9.0/Scripts) is created with the pip.exe and easy_install.exe executables, but when trying to invoke either of them, an error is raised, as the pip python module does not seem to be installed.
This can be tested by running this dockerfile:
$ docker build . --tag=mt5pyserver
$ docker run --name=prueba -it mt5pyserver bash
And then:
root#a169a4c4aae8:~# cd ".wine/drive_c/Program Files/python-3.9.0"
root#a169a4c4aae8:~/.wine/drive_c/Program Files/python-3.9.0# wine python.exe get-pip.py
Collecting pip
Using cached pip-20.2.3-py2.py3-none-any.whl (1.5 MB)
Collecting setuptools
Using cached setuptools-50.3.0-py3-none-any.whl (785 kB)
Collecting wheel
Using cached wheel-0.35.1-py2.py3-none-any.whl (33 kB)
Installing collected packages: pip, setuptools, wheel
WARNING: The scripts pip.exe, pip3.9.exe and pip3.exe are installed in 'C:\Program Files\python-3.9.0\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The scripts easy_install-3.9.exe and easy_install.exe are installed in 'C:\Program Files\python-3.9.0\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script wheel.exe is installed in 'C:\Program Files\python-3.9.0\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-20.2.3 setuptools-50.3.0 wheel-0.35.1
root#a169a4c4aae8:~/.wine/drive_c/Program Files/python-3.9.0# pip
bash: pip: command not found
root#a169a4c4aae8:~/.wine/drive_c/Program Files/python-3.9.0# wine Scripts/pip.exe
Traceback (most recent call last):
File "runpy.py", line 197, in _run_module_as_main
File "runpy.py", line 87, in _run_code
File "C:\Program Files\python-3.9.0\Scripts\pip.exe\__main__.py", line 4, in <module>
ModuleNotFoundError: No module named 'pip'
root#a169a4c4aae8:~/.wine/drive_c/Program Files/python-3.9.0# wine --version
wine-5.0 (Ubuntu 5.0-3ubuntu1)
root#a169a4c4aae8:~/.wine/drive_c/Program Files/python-3.9.0#
root#a169a4c4aae8:~/.wine/drive_c/Program Files/python-3.9.0# wine Scripts/pip.exe
Traceback (most recent call last):
File "runpy.py", line 197, in _run_module_as_main
File "runpy.py", line 87, in _run_code
File "C:\Program Files\python-3.9.0\Scripts\pip.exe\__main__.py", line 4, in <module>
ModuleNotFoundError: No module named 'pip'
root#a169a4c4aae8:~/.wine/drive_c/Program Files/python-3.9.0#
What I need is to correctly install pip in the in-windows python interpreter. There is an underlying reason: package MetaTrader5 only exists for windows python versions. In the end, I'd like to install that package and also aiohttp. The server will then make use of those packages as described in the MetaTrader5 documentation for Python integration and some magic on my own.
What can I do to avoid getting that error?
Have a look at this Dockerfile. It might give you some insight. The approach used is completely different.
Some noteworthy differences between this Dockerfile and your setup:
Use wine from the WineHQ's package repository, not Ubuntu's.
Download python msi setup files from python.org and install them using wine msiexec.
Here's an except from the Dockerfile:
...
...
ARG PYINSTALLER_VERSION=4.0
...
...
RUN set -x \
&& for msifile in `echo core dev exe lib path pip tcltk tools`; do \
wget -nv "https://www.python.org/ftp/python/$PYTHON_VERSION/amd64/${msifile}.msi"; \
wine msiexec /i "${msifile}.msi" /qb TARGETDIR=C:/Python37; \
rm ${msifile}.msi; \
done \
&& cd /wine/drive_c/Python37 \
&& echo 'wine '\''C:\Python37\python.exe'\'' "$#"' > /usr/bin/python \
&& echo 'wine '\''C:\Python37\Scripts\easy_install.exe'\'' "$#"' > /usr/bin/easy_install \
&& echo 'wine '\''C:\Python37\Scripts\pip.exe'\'' "$#"' > /usr/bin/pip \
&& echo 'wine '\''C:\Python37\Scripts\pyinstaller.exe'\'' "$#"' > /usr/bin/pyinstaller \
&& echo 'wine '\''C:\Python37\Scripts\pyupdater.exe'\'' "$#"' > /usr/bin/pyupdater \
&& echo 'assoc .py=PythonScript' | wine cmd \
&& echo 'ftype PythonScript=c:\Python37\python.exe "%1" %*' | wine cmd \
&& while pgrep wineserver >/dev/null; do echo "Waiting for wineserver"; sleep 1; done \
&& chmod +x /usr/bin/python /usr/bin/easy_install /usr/bin/pip /usr/bin/pyinstaller /usr/bin/pyupdater \
&& (pip install -U pip || true) \
&& rm -rf /tmp/.wine-*
ENV W_DRIVE_C=/wine/drive_c
ENV W_WINDIR_UNIX="$W_DRIVE_C/windows"
ENV W_SYSTEM64_DLLS="$W_WINDIR_UNIX/system32"
ENV W_TMP="$W_DRIVE_C/windows/temp/_$0"
# install Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019 dll files
RUN set -x \
&& rm -f "$W_TMP"/* \
&& wget -P "$W_TMP" https://aka.ms/vs/16/release/vc_redist.x64.exe \
&& cabextract -q --directory="$W_TMP" "$W_TMP"/vc_redist.x64.exe \
&& cabextract -q --directory="$W_TMP" "$W_TMP/a10" \
&& cabextract -q --directory="$W_TMP" "$W_TMP/a11" \
&& cd "$W_TMP" \
&& rename 's/_/\-/g' *.dll \
&& cp "$W_TMP"/*.dll "$W_SYSTEM64_DLLS"/
# install pyinstaller
RUN /usr/bin/pip install pyinstaller==$PYINSTALLER_VERSION
...
...
Also, why do you have to install pip when Python 2 >=2.7.9 or Python 3 >=3.4 already includes pip?
Further note that it is recommended to put related commands (apt-get update/install) in the same RUN step.

How do you setup python3.2 on ubuntu 14.04 for testing with tox?

Trying to use tox to run tests before pushing, but I keep running into errors like:
ERROR: py26: InterpreterNotFound: python2.6
ERROR: py32: InterpreterNotFound: python3.2
ERROR: py34: InterpreterNotFound: python3.3
apt-cache search isn't offering any packages that look like they will help. How do you load all these versions of the interpreter for ubuntu14.04?
Obviously, Ubuntu doesn't ship all historic versions of Python. But you can use deadsnakes PPA which has everything from 2.3 to 3.4.
For one project I used drone.io CI service with, I had the following tox section I ran before actual test envs.
[testenv:setupdrone]
whitelist_externals = /bin/bash
commands =
bash -c "echo 'debconf debconf/frontend select noninteractive' | sudo debconf-set-selections"
bash -c "sudo add-apt-repository ppa:fkrull/deadsnakes &> /dev/null"
bash -c "sudo apt-get update &> /dev/null"
bash -c "sudo apt-get -y install python2.6 python3.4 &> /dev/null"

Install node.js using alternate install of PYTHON

My server is running CentOS 5.8 and uses PYTHON 2.4
I installed an alternate version of PYTHON 2.7 to use to install node.js
I have followed several different tutorials to get to this point and need a little help to finish
i am in the node directory and used this command for configure
/usr/bin/env python2.7 ./configure
when I ran the make command there was an error.
File "../../tools/js2c.py", line 387
except Error as e:
^
SyntaxError: invalid syntax
make[1]: *** [/root/node/out/Release/obj/gen/libraries.cc] Error 1
make[1]: Leaving directory `/root/node/out'
make: *** [node] Error 2
I believe that's because it's using the 2.4 version of python. How can I force the make and make install command use my alternate install of python 2.7?
I'm a complete beginner to linux commands.
I accomplished this by doing the following. Full process
yum update -y
yum -y groupinstall "Development Tools"
installed git ... followed this (https://stackoverflow.com/a/8327476/888640)
Installed alternate version of PYTHON
wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
tar -xvzf Python-2.7.2.tgz
cd Python-2.7.2
./configure
make altinstall
cd
use the correct python version
mv /usr/bin/python /usr/bin/python.old
ln -s /usr/local/bin/python2.7 /usr/bin/python
install node
cd node
./configure
make
make install
change back to normal version of python
mv /usr/bin/python.old /usr/bin/python

Do the python bindings for libtorrent-rasterbar work with Python 3 ?

I have Python 3.4 (32-bit) installed, and I installed the python-libtorrent-0.16.16.win32.msi on top of that.
My test code says:
ImportError: DLL load failed: %1 is not a valid Win32 application.
My google results suggest this works fine with Python 2.7. Is that the solution? I have to down-grade my Python?
NO. Libtorrent doesn't support Python 3.
It compiles but doesn't work due to Python 3 utf8 handling difference.
There was an unsuccessful effort to make it work a while back
https://code.google.com/p/libtorrent/issues/detail?id=449
Current trunk even contains invalid Python 3 i.e.
http://sourceforge.net/p/libtorrent/code/HEAD/tree/trunk/bindings/python/setup.py
Line 70 > 'print cmdline'
For some reason there is an Ubuntu python3-libtorrent package which confuses people, but it definitely doesn't work, neither does manual compilation.
steps:
apt-get build-dep libtorrent-rasterbar
export 'PYTHON_VERSION=3.4'; export 'PYTHON=/usr/bin/python3.34'
./configure LDFLAGS="-L/usr/lib/python3.4/config-3.4m-x86_64-linux-gnu/" --enable-python-binding --enable-geoip=no
--with-boost-python=boost_python-py34
ldconfig
>> python
import libtorrent
ses = libtorrent.session()
ses.save_state()
"UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa2 in position 0: invalid start byte"
It does support python3
This docker file works for me (libtorrent - local dir with the lib been checked out to version needed)
FROM debian:buster-slim
WORKDIR /app/libtorrent
COPY debian/backports.list /etc/apt/sources.list.d/
RUN apt-get update
RUN apt-get install -y -t buster-backports checkinstall
RUN apt-get install -y build-essential libboost-system-dev libboost-python-dev libboost-chrono-dev libboost-random-dev libssl-dev
RUN apt-get install -y autoconf automake libtool
ADD libtorrent /app/libtorrent
RUN ./autotool.sh
# RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1
ENV PYTHON=/usr/bin/python3.7
RUN ./configure --enable-python-binding --with-libiconv
RUN make
RUN checkinstall
RUN ldconfig

Categories

Resources