ERROR when trying to build chromium on my own computer - python-2.7

Right now, I am tring to build Chromium on my own computer under instructions at https://chromium.googlesource.com/chromium/src/+/master/docs/linux/build_instructions.md#Build-Chromium
At first, it went smoothly. However when I run
$ autoninja -C out/Default chrome
when I run this to start build. It started. And then an error occured and the build process is terminated.
The error is
NameError: name 'unicode' is not defined" and I know it is a common error associated with the difference between python2 and python3.
However, I don't know how to let the ninja use only python2 and avoid this bug.
If you can help me, I will really appreciate it.

I recently ran into this issue when attempting to home build the Brave browser, which is chromium based. It appears that chromium build is based on python2, which is fine, but uses plain calls to "python" in the scripts. Obviously, essentially all modern distros put a symlink to python3 at python in the PATH (generally /usr/bin/python -> /usr/bin/python3). I still retain hope that there is a way to configure the "python path" in the build system, but have not found it and I am not too familiar with ninja.
The first way I "solved" this, and managed a successful build is one I consider a hack and do not recommend as a solution without the stipulation that it leaves your system broken so don't run too many other things. This is to manually temporarily update the symlink. Assuming you have both /usr/bin/python2 and /usr/bin/python3 on your system, remove the symlink at /usr/bin/python and replace it with one to python2:
sudo rm /usr/bin python
sudo ln -s /usr/bin/python2 /usr/bin/python
You can then run the chromium build, and reverse the above change when completed. Note that anything on your system that requires python3 to be at the symlink python cannot be run during this time. I have successfully used this technique to build Brave (and then reverse the change after the build completed).
I can offer you some other options too. One is to set up pyenv. If you search for that, you will find it is a suite that allows you to manage multiple python versions and have different directories use different ones. I researched this, and assume it can work, but have not done it myself.
The next option, which I am currently undertaking right now, is basically a manual watered down version of what pyenv does. I will let you know how it goes. The essence is to add a symlink in the path that will redirect python calls for that instance of the shell (and all subshells it creates). Assuming you are in the source directly at the obvious path:
mkdir .shims
ln -s /usr/bin/python2 .shims/python
export PATH=/home/yourname/src/Chromium/.shims:$PATH
python --version
This should print out whatever version of python2 you have rather than python. Anytime you come back to work here, you have to export the new PATH again. The rest of your system is unaffected, and still finds python3 at python. You can open up a new terminal and type python --version to verify that.

I have Chromium building on Fedora 33. Somewhere in the Chromium build, /usr/bin/python is getting run explicitly. On Fedora, that means Python 3.
If you change /usr/bin/python to point to python2.7, I bet your build will work.
Creating aliases for "python" won't work.
If this works, consider using the alternatives command to easily change /usr/bin/python:
alternatives command for /usr/bin/python

Related

YouCompleteMe completed failed

➜ YouCompleteMe git:(master) ./install.py --clang-completer
Searching Python 3.7 libraries...
ERROR: Python headers are missing in /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/Headers.
I used brew to install python and have not downloaded Xcode
Ended here after having the same problem. The problem in my case was that the python version that was being used was not the correct one. So even after executing:
brew reinstall python3
I was getting the error.
What finally fixed the issue was to explicitly state which python interpreter to use:
/usr/local/bin/python3.9 install.py --all
In my case, I needed to close iTerm and re-open it. So if reinstalling python3 didn't work, try this or alternatively:
source ~/.zshrc
I encountered this problem because of multiple python installations on my machine, one is anaconda python, another is standard python.
I will introduce every step I've done to deal with it.
At first, I used anaconda Python to build YCM. The YCM Server cannot be started and I got the cause from this issue. But when I tried to install YCM using standard Python with the command:
$ /usr/bin/python3 install.py --go-completer --clang-completer --go-completer
The result of execution is an error message as follows:
ERROR: Python headers are missing in /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Headers.
The installation failed; please see above for the actual error. In order to get more information, please re-run the command, adding the --verbose flag. If you think this is a bug and you raise an issue, you MUST include the *full verbose* output.
For example, run:/Library/Developer/CommandLineTools/usr/bin/python3 /Users/jianxue/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py --go-completer --clang-completer --go-completer --verbose
I was so confused for a long time. And at last, I tried to deactivate the anaconda python, and the standard Python was the default one now.
python3 install.py --go-completer --clang-completer --go-completer
Succeed! I guess anaconda overrides the python configurations. Although I used the standard python, the c header for python still couldn't be found by OS.

how to revert make install and use make altinstall

i had followed this tutorial in other to overwrite python2.7 with python 3.4.4 and it worked very nice. Only one thing was wrong. typing python, still goes to python2.7 and python3 goes to python3.4.4. so from what i learnt is that
It is critical that you use make altinstall when you install your custom version of Python. If you use the normal make install you will end up with two different versions of Python in the filesystem both named python. This can lead to problems that are very hard to diagnose.
Please help me revert this.
went through this blog Install Python on Linux (Centos).
I had to re-run make altinstall with sudo command of course. I tried this after that
`sudo ln -s /usr/local/bin/python3.4 /usr/local/bin/python`.
which have me
ln: creating symbolic link `/usr/local/bin/python': File exists
I had to delete the path /usr/local/bin/python.
and then tried again.
problem solved

Pyomo can't locate GLPK solver

I'm trying to use the GLPK solver with Pyomo. I have a working model that's been tested, but keep getting an error saying GLPK can't be found.
WARNING: Could not locate the 'glpsol' executable, which is required for solver 'glpk'
I've installed glpk sucessfully. I also added the directory to my path variable so the executed can be called globally. I tested this with glpsol --help from my command line, and see the help info printed.
The below thread says it should be working, but alas, it is not.
How do you install glpk-solver along with pyomo in Winpython
Any ideas?
This answer is late but I want to share the solution that worked for me.
solvername='glpk'
solverpath_folder='C:\\glpk\\w64' #does not need to be directly on c drive
solverpath_exe='C:\\glpk\\w64\\glpsol' #does not need to be directly on c drive
I used to do this:
sys.path.append(solverpath_folder)
solver=SolverFactory(solvername)
This works for the cbc solver in coin-or but it does not work for glpk. Then I tried something different:
solver=SolverFactory(solvername,executable=solverpath_exe)
This worked for both cbc and glpk. No idea why this works (I really didn't do anything else).
Version: Python 2.7 or Python 3.7 (tested both), glpk 4.65
You can install glpk solver using this command -
brew install glpk
Installing the glpk package worked for me. As I use Anaconda:
conda install -c conda-forge glpk
This was after already including the 'glpsol' exectuable's folder path in my PATH variables.
So it looks like the set path variable is not handled by your Python installation.
A normal Python installation is set up for a seperated "PYTHONPATH" environment variable to look up additional modules.
There is also the option to make an entry in the windows registry or (like you already mentioned) move the files to the Python home directory, which is recognized relative to your installation directory if "PYTHONHOME" is not set.
More information in the Python Documentary under 3.3.3.
https://docs.python.org/2/using/windows.html#finding-modules
I was having the same issue. I don't know if this is a solution but it definitely got the solver working.
After downloading the Windows installation. I copied all the files in the w64 folder and pasted them directly into my Python working directory.
After that my python code could locate the solver.
NOTE: this was for Python 3.4.3.4, Windows 8.1 64 bit
Reading the source code here suggests you try:
from pyutilib.services import register_executable, registered_executable
register_executable(name='glpsol')
maybe will it give a clue
I had the same issue on Windows 10 and it was down to glpk being installed in a different conda environment. Full steps for installing pyomo and glpk below.
Test the installation by running 'Repeated Solves' example from https://pyomo.readthedocs.io/en/latest/working_models.html
Instructions (run at an anaconda prompt)
conda create --name myenv
conda activate myenv
conda install -c conda-forge pyomo
conda install -c conda-forge pyomo.extras
conda install -c conda-forge glpk
Run spyder from myenv so that if finds everything
spyder activate myenv
Here is the relevant part where pyomo 6.2 searches for the glpsol executable
https://github.com/Pyomo/pyomo/blob/568c6595a56570c6ea69c3ae3198b73b9f473abd/pyomo/common/fileutils.py#L288
def _path():
return (os.environ.get('PATH','') or os.defpath).split(os.pathsep)
There are two options to solve the PATH problem:
Putting the executable in an available folder in PATH (recommended practice). The glpsol executable must be in one of the folders present in the PATH system environment variable. Use in your code print(os.environ['PATH']) to see the available folders and put it there.
Adding the folder to PATH at runtime. You can add it to the system PATH statically or use code to add it dynamically (only while your script is running):
GLPK_FOLDER_PATH = "path/to/glpk"
os.environ["PATH"] += os.pathsep + str(GLPK_FOLDER_PATH)
In my case, my Python project has a virtual environment .venv, and I have an installation process that pastes the files essential to the glpsol executable when I install the project inside the .venv/Scripts folder. Because that folder is added automatically to the system PATH when Python is called from the virtual environment, libraries like Pyomo can find it. And I don't have to remember to add the folder to PATH at runtime whenever I want to use Pyomo.
For anyone that has the same issue, I found a workaround (not a solution!). I copied all the glpk files into my C:/Python27 directory, and (Surprise!) Python can now find them.
I'll hold out for a real solution before accepting this one.

Install Spatialite for python (GeoDjango) on OS X

I am tearing my hair out trying to install Spatialite for GeoDjango!
I am already using Homebrew, it's generally easy and convenient so I initially tried to follow the Homebrew instructions for GeoDjango.
But this stops short of installing any database, i.e. Spatialite. The next step is to try and install Spatialite itself, but there are no Homebrew-specific instructions provided by Django docs.
I found this tutorial which looks perfect - a Homebrew and virtualenv-friendly install of Spatialite for GeoDjango.
But it doesn't work... it appears that my pysqlite is linked against the non-spatial-enabled version of SQLite that comes with OS X, rather than the Spatial-ised one I installed from Homebrew, I get this error when Django tried to connect to the db:
"The pysqlite library does not support C extension loading. Both SQLite and pysqlite must be configured to allow the loading of extensions to use SpatiaLite."
The author of pysqlite hasn't responded to my pleas for help on Github and I haven't found anything via Google.
So I went back to the drawing board and decided to follow the "Mac OS X-specific instructions" in the GeoDjango docs... by installing the various geo libs from the KyngChaos binary packages.
The docs say "Install the packages in the order they are listed above" but I found I couldn't install UnixImageIO without installing PROJ first. The link in the docs to download Spatialite binaries (http://www.gaia-gis.it/spatialite-2.3.1/binaries.html) is broken so I used the "Spatialite Tools v4.1" from KyngChaos instead.
Proceeding to the next step I get this error:
$ spatialite geodjango.db "SELECT InitSpatialMetaData();"
SQLite header and source version mismatch
2013-10-17 12:57:35 c78be6d786c19073b3a6730dfe3fb1be54f5657a
2013-09-03 17:11:13 7dd4968f235d6e1ca9547cda9cf3bd570e1609ef
Not really sure what's wrong at this point.
There is someone else here on SO who has gone the KyngChaos route and just ends up with the same "Both SQLite and pysqlite must be configured to allow the loading of extensions" error I got from the Homebrew route anyway.
I found this ticket #17756 for adding pyspatialite support to Django - pyspatialite is supposed to be an easier way to pip install everything but unfortunately it doesn't work either (see comments towards bottom of ticket).
I'm a bit reluctant to start trying to build everything from source by hand as it seems likely I'll just run into the same problems again, but spending hours Googling for info about cryptic compiler errors, magic flags and paths etc along the way.
I'm about ready to give up and just use Postgres/PostGIS.
I was able to get this working now, using the tip here:
https://github.com/ghaering/pysqlite/issues/60#issuecomment-50345210
I'm not sure if it was using the real paths that fixed it, or just the Homebrew kegs or underlying packages have been updated and now install cleanly. Still, it works now.
I reproduce below the steps I took:
brew update
brew install sqlite # 3.8.5
brew install libspatialite # 4.2.0
brew install spatialite-tools # 4.1.1
git clone https://github.com/ghaering/pysqlite.git
cd pysqlite
(where brew reported I had existing versions I unlinked them and installed the latest as commented above)
then edited setup.cfg to comment out #define=SQLITE_OMIT_LOAD_EXTENSION and specify the paths:
include_dirs=/usr/local/opt/sqlite/include
library_dirs=/usr/local/opt/sqlite/lib
activated the virtualenv where I want it installed, then
python setup.py build
python setup.py install
(build_static still fails with clang: error: no such file or directory: 'sqlite3.c')
(maybe I should have done pip install . as suggested in the github issue)
now the spatialite geodjango.db "SELECT InitSpatialMetaData();" succeeds, albeit with an ignorable error:
InitSpatiaMetaData() error:"table spatial_ref_sys already exists"
i.e. it's probably not even necessary to run that command
When I was istalling this i follow this instructions https://docs.djangoproject.com/en/dev/ref/contrib/gis/install/spatialite/#pysqlite2
pysqlite2
If you’ve decided to use a newer version of pysqlite2 instead of the sqlite3 Python stdlib module, then you need to make sure it can load external extensions (i.e. the required enable_load_extension method is available so SpatiaLite can be loaded).
This might involve building it yourself. For this, download pysqlite2 2.6, and untar:
$ wget https://pypi.python.org/packages/source/p/pysqlite/pysqlite-2.6.3.tar.gz
$ tar xzf pysqlite-2.6.3.tar.gz
$ cd pysqlite-2.6.3
Next, use a text editor (e.g., emacs or vi) to edit the setup.cfg file to look like the following:
[build_ext]
#define=
include_dirs=/usr/local/include
library_dirs=/usr/local/lib
libraries=sqlite3
#define=SQLITE_OMIT_LOAD_EXTENSION
I had the same error: SQLite header and source version mismatch.
For me it was enough to update libsqlite3-dev.
After that invoking $ spatialite geo.db "SELECT InitSpatialMetaData();" creates proper database.

Uninstall python.org version of python2.7 in favor of default OS X python2.7

I'm running OS X 10.8.2 and I believe that by default this comes with Python 2.7.3. I previously had Python 2.7.2 installed from python.org and would like to scrap it to basically reset my system's default python to that which comes pre-installed. The reason being that whenever I launch any *.py file IDLE refuses to open (even when specifying my installed Python2.7.2 IDLE) and I want to get things up to date.
Although I never use it, I do have MacPorts installed and I'm seeing that it did a bunch of stuff to my Python path - notably changing my Python 2.7 path to "/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}", so I don't know if this makes a difference.
Can anybody recommend a course of action here? I'm happy to provide additional information if needed.
There are three things making up the python.org python install which need to be removed. These steps worked for me:
Remove the actual Python install:
rm -rf /Library/Frameworks/Python.framework
Remove the Python.org extra applications by deleting the folder at /Applications/Python 2.7:
rm -rf /Applications/Python\ 2.7
Remove the symlinks to the python executables from your /usr/local/bin directory:
find /usr/local/bin -type l -and -lname "/Library/Frameworks/Python.framework*" -delete
Remove or comment out these lines from your bash startup script (either ~/.profile or ~/.bash_profile):
# Setting PATH for Python 2.7
# The orginal version is saved in .profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
Some of these steps may require super-user privileges via e.g. sudo. Once this is done, you should have only the original Mac.
Based on documentation at http://docs.python.org/2/using/mac.html