gn scripts are run with the wrong Python version ("a bytes-like object is required, not 'str'") - chromium

When building Chromium or libwebrtc with gn on macOS (Catalina 10.15), I get errors from the Python build scripts about bytes and str. For example:
src [heads/master●] % gn gen out/ios_64 --args='target_os="ios" target_cpu="arm64"'
ERROR at //build/config/ios/ios_sdk.gni:109:21: Script returned non-zero exit code.
_ios_sdk_result = exec_script(script_name, ios_sdk_info_args, "scope")
^----------
Current dir: /Users/lynn/code/webrtc_ios/src/out/ios_64/
Command: python /Users/lynn/code/webrtc_ios/src/build/config/mac/sdk_info.py --get_sdk_info iphoneos
Returned 1.
stderr:
Traceback (most recent call last):
File "/Users/lynn/code/webrtc_ios/src/build/config/mac/sdk_info.py", line 107, in <module>
FillXcodeVersion(settings, args.developer_dir)
File "/Users/lynn/code/webrtc_ios/src/build/config/mac/sdk_info.py", line 59, in FillXcodeVersion
settings['xcode_version'] = FormatVersion(lines[0].split()[-1])
File "/Users/lynn/code/webrtc_ios/src/build/config/mac/sdk_info.py", line 43, in FormatVersion
major, minor, patch = SplitVersion(version)
File "/Users/lynn/code/webrtc_ios/src/build/config/mac/sdk_info.py", line 30, in SplitVersion
version = version.split('.')
TypeError: a bytes-like object is required, not 'str'
See //build/config/sysroot.gni:67:3: whence it was imported.
import("//build/config/ios/ios_sdk.gni")
^--------------------------------------
See //build/config/linux/pkg_config.gni:5:1: whence it was imported.
import("//build/config/sysroot.gni")
^----------------------------------
See //BUILD.gn:15:1: whence it was imported.
import("//build/config/linux/pkg_config.gni")
^-------------------------------------------
When I edit the offending Python script to print(sys.version), it shows that it is running Python 3, even though the scripts are supposed to running with the bundled virtual Python 2.7 environment defined in .vpython.
How do I configure gn to run these scripts with the appropriate Python version?

It seems exec_script is running these scripts with the machine Python version. gn help exec_script says:
The default script interpreter is Python ("python" on POSIX, "python.exe" or
"python.bat" on Windows). This can be configured by the script_executable
variable, see "gn help dotfile".
For me, python points to Python 3. So I had to add this line to the end of the .gn dotfile:
script_executable = "vpython"
Now the build uses the virtual Python defined in .vpython, which is Python 2.7.
(The vpython executable is provided by Chromium depot_tools, just like gn.)

Related

PyQt5 Modules not Found?

This is a complete fresh install of MacOS!
Platform:
Apple MacBook Air - M1
MacOS Monterey
Package Info:
Homebrew: 3.3.14
pip: 22.0.3
Python: 3.9.10 (installed via 'brew install python')
Latest-Xcode
My $PATH environment:
/opt/homebrew/bin
/opt/homebrew/sbin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
I tried adding a combination of these to my $PATH, to no avail:
/opt/homebrew/lib/python3.9/site-packages
/opt/homebrew/Cellar/pyqt#5/5.15.6/lib/python3.9/site-packages/PyQt5
/opt/homebrew/lib/python3.9/site-packages/PyQt5
/opt/homebrew/opt/pyqt#5/5.15.6/bin
/opt/homebrew/opt/qt#5/5.15.6/bin
What I want to do:
pip install pyqt5
What happens when I try:
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... error
error: subprocess-exited-with-error
× Preparing metadata (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [29 lines of output]
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 156, in prepare_metadata_for_build_wheel
hook = backend.prepare_metadata_for_build_wheel
AttributeError: module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
main()
File "/opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 160, in prepare_metadata_for_build_wheel
whl_basename = backend.build_wheel(metadata_directory, config_settings)
File "/opt/homebrew/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sipbuild/api.py", line 51, in build_wheel
project = AbstractProject.bootstrap('pep517')
File "/opt/homebrew/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sipbuild/abstract_project.py", line 83, in bootstrap
project.setup(pyproject, tool, tool_description)
File "/opt/homebrew/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sipbuild/project.py", line 594, in setup
self.apply_user_defaults(tool)
File "project.py", line 63, in apply_user_defaults
super().apply_user_defaults(tool)
File "/opt/homebrew/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pyqtbuild/project.py", line 70, in apply_user_defaults
super().apply_user_defaults(tool)
File "/opt/homebrew/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sipbuild/project.py", line 241, in apply_user_defaults
self.builder.apply_user_defaults(tool)
File "/opt/homebrew/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pyqtbuild/builder.py", line 67, in apply_user_defaults
raise PyProjectOptionException('qmake',
sipbuild.pyproject.PyProjectOptionException
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
If I install it this way, I get no errors:
brew install pyqt#5
But my VS Code shows up like this, and none of submodules work:
My program used to work just fine, but I had recently installed Python 3.10 and have since uninstalled it. Ever since the new Python install, I've had this issue. Not sure how to tackle this. Thank you!
I've asked this question a number of different ways in a number of different places; none of the suggested answers work for me.
The closest thing to an answer that I got to was this:
https://www.zhihu.com/question/437075754/answer/1993415429
If you're unable to read it, it suggests this:
Pre-work, install homebrew, python 3.9.
First enter in the terminal:
brew install pyqt5
echo 'export PATH="/opt/homebrew/opt/qt#5/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/pyqt#5/5.15.4_1/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
Then, copy all the contents of
/opt/homebrew/Cellar/pyqt#5/5.15.4_1/lib/python3.9/site-packages to
lib/python3.9/site-packages folder. If your homebrew installation
address and python installation address are not the default, you need
to modify these two addresses.
Finally, try it in python
import PyQt5
But this didn't work for me, either.
In the end, I ended up just installing PyQt6:
pip install PyQt6
The install completed without any errors. Now I am working on updating my code. Hopefully this will be useful for someone else coming here from an angry Google search. Code on, my friends.
I had the issue as yours. I solve with the following command.
pip3 install pyqt5
my install setup is
1.brew install qt
2.brew install libxml2
reference by TheCrazySwede answer ↓↓↓
3.brew install pyqt5
enter image description here
4.brew cleanup pyqt#5
5.echo 'export PATH="/opt/homebrew/opt/qt#5/bin:$PATH"' >> ~/.zshrc
6.echo 'export PATH="/opt/homebrew/opt/pyqt#5/5.15.4_1/bin:$PATH"' >> ~/.zshrc
7.source ~/.zshrc
8.pip3 install pyqt5-sip
9.pip3 install pyqt5
enter image description here
enter image description here
10.pip3 install lxml
11.make qt5py3
I hope can help for you.

While running TensorFlow's classify_image, getting AttributeError: 'module' object has no attribute 'gfile'

I am getting this error while running the sample file given with TensorFlow, in the imagenet model,
File "classify_image.py", line 154, in run_inference_on_image
if not tf.gfile.Exists(image):
AttributeError: 'module' object has no attribute 'gfile'
I have tried installing using both, from pip as well as source, on virtualserver as well, still I get this error.
There are two ways to go about solving this problem:
Option 1
This is an expansion on Yaroslav's comment above, and is easier than option 2.
Modify classify_image.py as follows:
Replace all instances of tf.gfile.Exists to os.path.exists, and
replace all instances of tf.gfile.GFile and tf.gfile.FastGFile to open
Then run the modified classify_image.py, and it should work.
Option 2
Update tensorflow to the latest version that includes gfile as described here
However, after you do that, you might encounter the following error when you try to run classify_image.py:
$ python classify_image.py
>> Downloading inception-2015-12-05.tgz 100.0%
Succesfully downloaded inception-2015-12-05.tgz 88931400 bytes.
[libprotobuf ERROR google/protobuf/src/google/protobuf/io/coded_stream.cc:207] A protocol message was rejected because it was too big (more than 67108864 bytes). To increase the limit (or to disable these warnings), see CodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h.
Traceback (most recent call last):
File "classify_image.py", line 213, in <module>
tf.app.run()
File "/Users/USERNAME/.virtualenvs/mlnd/lib/python2.7/site-packages/tensorflow/python/platform/default/_app.py", line 30, in run
sys.exit(main(sys.argv))
File "classify_image.py", line 209, in main
run_inference_on_image(image)
File "classify_image.py", line 159, in run_inference_on_image
create_graph()
File "classify_image.py", line 141, in create_graph
graph_def.ParseFromString(f.read())
google.protobuf.message.DecodeError: Error parsing message
To fix this, you can change a line in the source code as described here and then recompile tensorflow on your machine.
Option 2 might be a bit of work, especially if you're on a Mac.
The following steps helped me resolve the issue
update tensorflow as described here https://www.tensorflow.org/versions/r0.7/get_started/os_setup.html
2.For me this resulted in protobuf error. To resolve I ran
$sudo pip uninstall protobuf
$sudo pip install --upgrade
https://storage.googleapis.com/tensorflow/mac/tensorflow-0.7.1-cp27-none-any.whl

ImportError: No module named _scproxy

I tried to make Sage from the source but I failed. It seems that the library _scproxy is missing on Yosemite. I haven't found a very helpful aid here on SO and everywhere on the net. If someone can help me. Here is the log :
Found local metadata for setuptools-12.4
Found local sources at /Users/sam/Downloads/sage-6.7/upstream/setuptools-12.4.tar.gz
Checksum: 427e916ad99a704af54b7aa3124bd52d4ebf04d3 vs 427e916ad99a704af54b7aa3124bd52d4ebf04d3
setuptools-12.4
====================================================
Setting up build directory for setuptools-12.4
Finished set up
****************************************************
Host system:
Darwin dhcp-147-65-172-203.impa.br 14.3.0 Darwin Kernel Version 14.3.0: Mon Mar 23 11:59:05 PDT 2015; root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
****************************************************
C compiler: gcc
C compiler version:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/Users/sam/Downloads/sage-6.7/local/libexec/gcc/x86_64-apple-darwin14.3.0/4.9.2/lto-wrapper
Target: x86_64-apple-darwin14.3.0
Configured with: ../src/configure --prefix=/Users/sam/Downloads/sage-6.7/local --with-local-prefix=/Users/sam/Downloads/sage-6.7/local --with-gmp=/Users/sam/Downloads/sage-6.7/local --with-mpfr=/Users/sam/Downloads/sage-6.7/local --with-mpc=/Users/sam/Downloads/sage-6.7/local --with-system-zlib --disable-multilib --disable-nls --enable-languages=c,c++,fortran --disable-libitm --with-build-config=bootstrap-debug --without-isl --without-cloog
Thread model: posix
gcc version 4.9.2 (GCC)
****************************************************
patching file setuptools/command/easy_install.py
Hunk #1 succeeded at 1491 (offset 45 lines).
Hunk #2 succeeded at 1529 with fuzz 1 (offset 45 lines).
Hunk #3 succeeded at 1555 (offset 45 lines).
patching file pkg_resources/__init__.py
Traceback (most recent call last):
File "setup.py", line 21, in <module>
exec(init_file.read(), command_ns)
File "<string>", line 11, in <module>
File "/Users/sam/Downloads/sage-6.7/local/var/tmp/sage/build/setuptools-12.4/src/setuptools/__init__.py", line 11, in <module>
from setuptools.extension import Extension
File "/Users/sam/Downloads/sage-6.7/local/var/tmp/sage/build/setuptools-12.4/src/setuptools/extension.py", line 8, in <module>
from .dist import _get_unpatched
File "/Users/sam/Downloads/sage-6.7/local/var/tmp/sage/build/setuptools-12.4/src/setuptools/dist.py", line 16, in <module>
from setuptools.depends import Require
File "/Users/sam/Downloads/sage-6.7/local/var/tmp/sage/build/setuptools-12.4/src/setuptools/depends.py", line 6, in <module>
from setuptools import compat
File "/Users/sam/Downloads/sage-6.7/local/var/tmp/sage/build/setuptools-12.4/src/setuptools/compat.py", line 19, in <module>
from SimpleHTTPServer import SimpleHTTPRequestHandler
File "/Users/sam/Downloads/sage-6.7/local/lib/python/SimpleHTTPServer.py", line 16, in <module>
import urllib
File "/Users/sam/Downloads/sage-6.7/local/lib/python/urllib.py", line 1399, in <module>
from _scproxy import _get_proxy_settings, _get_proxies
ImportError: No module named _scproxy
real 0m0.113s
user 0m0.059s
sys 0m0.037s
************************************************************************
Error installing package setuptools-12.4
************************************************************************
Please email sage-devel (http://groups.google.com/group/sage-devel)
explaining the problem and including the relevant part of the log file
/Users/sam/Downloads/sage-6.7/logs/pkgs/setuptools-12.4.log
Describe your computer, operating system, etc.
If you want to try to fix the problem yourself, *don't* just cd to
/Users/sam/Downloads/sage-6.7/local/var/tmp/sage/build/setuptools-12.4 and type 'make' or whatever is appropriate.
Instead, the following commands setup all environment variables
correctly and load a subshell for you to debug the error:
(cd '/Users/sam/Downloads/sage-6.7/local/var/tmp/sage/build/setuptools-12.4' && '/Users/sam/Downloads/sage-6.7/sage' --sh)
When you are done debugging, you can type "exit" to leave the subshell.
************************************************************************
EDIT : Ok I don't know what was going on but I restarted for the beginning the building and this seems to work. I don't have any gcc. When i type gcc -v, one answer me that I have clang instead of it ... When i makeit at the first time, the console asked me to rename my directory opt/local because of homebrew. Is think that is what didn't work at the first time. I rename it opt/local during the compilation of sage ...
Probably this is due to a Python build (Sage's Python, that is) that didn't successfully build this module; see this sage-release thread. In principle http://trac.sagemath.org/ticket/17174 should have fixed it (see http://trac.sagemath.org/ticket/17169) but perhaps you are using a non-Sage gcc, such as homebrew? In that event you'll need to either make that change somewhere or perhaps to just use Sage's gcc, which you do with SAGE_INSTALL_GCC=yes (though that will take longer, of course). Good luck!

Install NumPy for Python 3.2.3 on OS X 10.7.4

I have been trying for months to get numpy installed for Python 3 but despite copious amounts of Googling and even posting to the numpy mailing list I am still no closer to a solution.
I have managed to get it installed via MacPorts but unfortunately there doesn't appear to be a port of MatPlotLib for Python 3 which is the main reason I am trying to install numpy...so I am a bit stuck...
I keep getting the same error whilst trying to build from the setup.py file. I have included the terminal output below.
Thanks for any help you can offer,
Adam.
Here is the terminal output:
lipo: can't figure out the architecture type of: /var/folders/zj/7xymy_2n3s71ws30v3v_qnlw0000gn/T//ccbRr0Hj.out
failure.
removing: _configtest.c _configtest.o
Running from numpy source directory.Traceback (most recent call last):
File "setup.py", line 214, in <module>
setup_package()
File "setup.py", line 207, in setup_package
configuration=configuration )
File "/Users/adammcnicol/Downloads/numpy-1.6.2rc1/build/py3k/numpy/distutils/core.py", line 186, in setup
return old_setup(**new_attr)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/distutils/core.py", line 148, in setup
dist.run_commands()
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/distutils/dist.py", line 917, in run_commands
self.run_command(cmd)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/distutils/dist.py", line 936, in run_command
cmd_obj.run()
File "/Users/adammcnicol/Downloads/numpy-1.6.2rc1/build/py3k/numpy/distutils/command/build.py", line 37, in run
old_build.run(self)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/distutils/command/build.py", line 126, in run
self.run_command(cmd_name)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/distutils/dist.py", line 936, in run_command
cmd_obj.run()
File "/Users/adammcnicol/Downloads/numpy-1.6.2rc1/build/py3k/numpy/distutils/command/build_src.py", line 152, in run
self.build_sources()
File "/Users/adammcnicol/Downloads/numpy-1.6.2rc1/build/py3k/numpy/distutils/command/build_src.py", line 169, in build_sources
self.build_extension_sources(ext)
File "/Users/adammcnicol/Downloads/numpy-1.6.2rc1/build/py3k/numpy/distutils/command/build_src.py", line 328, in build_extension_sources
sources = self.generate_sources(sources, ext)
File "/Users/adammcnicol/Downloads/numpy-1.6.2rc1/build/py3k/numpy/distutils/command/build_src.py", line 385, in generate_sources
source = func(extension, build_dir)
File "numpy/core/setup.py", line 410, in generate_config_h
moredefs, ignored = cocache.check_types(config_cmd, ext, build_dir)
File "numpy/core/setup.py", line 41, in check_types
out = check_types(*a, **kw)
File "numpy/core/setup.py", line 271, in check_types
"Cannot compile 'Python.h'. Perhaps you need to "\
SystemError: Cannot compile 'Python.h'. Perhaps you need to install python-dev|python-devel.
Well, I finally managed to get NumPy to install. Not sure it is the best method but it seems to work!
First of all i needed to install distribute:
curl http://python-distribute.org/distribute_setup.py | python3
Then I installed pip:
curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python3
After that I had to get pip on to my system path (again there are probably better ways):
Open Terminal
Type the following (single line):
sudo ln -s /Library/Frameworks/Python.framework/Versions/3.2/bin/pip /usr/local/bin
With distribute and pip installed I then installed Nose, which NumPy needs for testing or something:
Again, in Terminal type the following:
pip install nose
Now I needed to make sure I had the latest version of Xcode:
From the AppStore install the latest version of Xcode
If you still have a /Developer folder then rename it Developer-old (not sure whether this will cause problems for me later or not)
Open Terminal and create a symlink to the AppStore version of Xcode (single line):
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer /Developer
With all of that out of the way time to install NumPy:
Download the NumPy source from: http://sourceforge.net/projects/numpy/files/NumPy/1.6.2rc1/
Unarchive the file
Open Terminal again:
cd into the directory created by unarchiving the file e.g.
cd /Users/username/Downloads/numpy-1.6.2rc1
Type into the Terminal the following to change the complier used to build NumPy:
export CC=clang
export CXX=clang
export FFLAGS=-ff2c
export LDSHARED='clang -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -g' (this is a single line)
python3 setup.py build (this may take a while)
python3 setup.py install
Okay, assuming there were no errors NumPy should be installed. Time to test it out:
Open IDLE
In the Python Shell type:
import numpy
numpy.test('full')
This will test NumPy the final result I received with Python 3.2.3 was:
<nose.result.TextTestResult run=3192 errors=0 failures=1>
So the NumPy installation passes all except one test, which seems pretty good. I haven't had a chance to see if works properly yet as I am still struggling to get matplotlib installed...
Hope these instructions are useful to somebody!
Adam.
I'm using Python 3.3 and OS X 10.7, and I installed numpy using a much easier method than above. I'm posting here in case it can help someone.
Follow these steps:
Download the zip file from numpy on github, and unpack it wherever you want.
Open a terminal and cd to the directory
enter the command python3 setup.py build --fcompiler=gnu95 (requires gfortran. Enter gfortran -v to see if you've got it, I've got version 4.6.2)
enter python3 setup.py install
That's all it took for me. Running numpy.test('full') gives me some errors, however: http://pastebin.com/5XF0qAe5
I don't know what kind of errors I'm going to experience yet.
The above answer worked great for me, except that you mentioned this was for OS X 10.7 (same here) so my build command did complain about the line:
export LDSHARED='clang -bundle -undefined dynamic_lookup -arch i386
-arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -g' (this is a single line)
So, I just changed that to 10.7 and it worked fine. Apparently, for OS X 10.7, the /Developer/SDKs/ directory contains MacOSX10.7.sdk and MacOSX10.8.sdk. Thanks for the great answer!
I've come back to this answer a number of times, if you're using 10.8, you need to do a few things to get this to work (but I don't think you need the LDSHARED part).
Install XCode from Apple as well as the command line tools (this gets you the compilers you need).
set environment variables to point to clang and use easy_install (NOT distribute) to install, this line will work:
CC=clang CXX=clang FFLAGS=-ff2c easy_install numpy
Do not try to install other packages at the same time. The numpy install may exit claiming an error, but often it manages to install itself anyways (for example, if you try to install in a virtualenv, this may happen).
for me i installed python3 from their website and then to install numpy,
pip3 install numpy
it works!

Blender not working with Python

I'm trying to run an external script with blender 2.49b and 2.57
I tried with installing Python versions, 2.4, 2.6 and 2.7.
I'm getting this error in the console window.
Anyone have a clue of what I'm missing?
Traceback (most recent call last): File "", line 1, in File "C:\Program Files\Blender
2.49b.blender\scripts\blended_cities_24hook.py ", line 77, in
from random import randint,random,uniform File "C:\Python24\LIB\random.py", line 41, in
from warnings import warn as _warn File "C:\Python24\LIB\warnings.py", line 258, in
simplefilter("ignore", category=OverflowWarning, append=1) NameError: name 'OverflowWarning' is not defined
Computer Info:
Operating Sys: Win7 x64.
CPU: Intel.
Fixed it! In my sys vars, I had the Python path set to the 2.4 version, which doesn't work with these versions of blender.