How do I install de b2 command line with cmake - python

I have a c++ code that use boost functions. I want to install boost and link against my binary. But the boost repository doesn't have a cmake file and I coudn't use this repository as submodule. I could install boost using cmake. But to intall it, I have the b2 command line. I know the b2 command line is a python package.
My question: is possible to download this python package using a cmake file?
EDIT:
I know how to install de boost now with b2 command. But, I want only install de filesystem library. The boost directory has many content that I won't need. I have this cmake file, BUt I don't know how to exacly edited to archive my goal. I see a post here in stackoverflow that I can do something like that:
b2 tools/bcp
mkdir /tmp/interprocess
bcp interprocess /tmp/interprocess
But I don't know how to make this command line in side of a cmake file
my cmake file
cmake_minimum_required(VERSION 2.8)
include(ExternalProject)
# Download boost from git
SET (BOOST_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/boost/src/boost/lib/filesystem/include/boost/)
SET (BOOST_URL https://github.com/google/re2.git)
SET (BOOST_BUILD ${CMAKE_BINARY_DIR}/boost/src/boost)
get_filename_component(BOOST_STATIC_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/lib/libboost_filesystem.a ABSOLUTE)
SET (BOOST_INCLUDES ${RE2_BUILD})
if ( UNIX )
SET (BOOST_STATIC_LIBRARIES ${BOOST_BUILD}/libboost_filesystem.a)
endif ()
ExternalProject_Add(
boost
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/boost
GIT_REPOSITORY https://github.com/boostorg/boost.git
UPDATE_COMMAND ./bootstrap.sh --with-libraries=filesystem
CONFIGURE_COMMAND ""
BUILD_COMMAND ./b2 tools/bcp link=static install --prefix=${CMAKE_CURRENT_BINARY_DIR}/
BUILD_IN_SOURCE 1
INSTALL_COMMAND ""
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR/include/boost
})
set(Boost_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/include/boost)
set(Boost_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/lib/ibboost_filesystem.a)
EDIT
Guys, I want to do this by using git submodules.
I want use boost using submodules. But boost has a lot of submodules and I only want to get submodules from boost that is necessary to boost.filesystem
But When I use boost as submodule in my project and try to include the boost directory in cmake file, this error happen:
CMake Error at CMakeLists.txt:16 (add_subdirectory):
The source directory
/home/lais/testeBoost/lib/boost
does not contain a CMakeLists.txt file.

Related

ta-lib replit python install problem, ERROR: No matching distribution found for talib-binary

I use it on my windows machine by downloading its binary. I also use it in Heroku from its herokus build pack. I don't know what operating system replit use. But I try every possible commed like.
!pip install ta-lib
!pip install talib-binary
It's not working with replit. I thought it work like google co-lab but its not the same.
can anyone use TA-LIB with replit. if so. How you install it?
Getting TA-Lib work on Replit
(by installing it from sources)
Create a new replit with Nix toolset with a Python template.
In main.py write:
import talib
print (talib.__ta_version__)
This will be our test case. If ta-lib is installed the python main.py (executed in Shell) will return something like:
$ python main.py
b'0.6.0-dev (Jan 1 1980 00:00:00)'
We need to prepare a tools for building TA-Lib sources. There is a replit.nix file in your project's root folder (in my case it was ~/BrownDutifulLinux). Every time you execute a command like cmake the Nix reports that:
cmake: command not installed. Multiple versions of this command were found in Nix.
Select one to run (or press Ctrl-C to cancel):
cmake.out
cmakeCurses.out
cmakeWithGui.out
cmakeMinimal.out
cmake_2_8.out
If you select cmake.out it will add a record about it into the replit.nix file. And next time you call cmake, it will know which cmake version to launch. Perhaps you may manually edit replit.nix file... But if you're going to add such commands in a my way, note that you must execute them in Shell in your project root folder as replit.nix file is located in it. Otherwise Nix won't remember your choice.
After all my replit.nix file (you may see its content with cat replit.nix) content was:
{ pkgs }: {
deps = [
pkgs.libtool
pkgs.automake
pkgs.autoconf
pkgs.cmake
pkgs.python38Full
];
env = {
PYTHON_LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
# Needed for pandas / numpy
pkgs.stdenv.cc.cc.lib
pkgs.zlib
# Needed for pygame
pkgs.glib
# Needed for matplotlib
pkgs.xorg.libX11
];
PYTHONBIN = "${pkgs.python38Full}/bin/python3.8";
LANG = "en_US.UTF-8";
};
}
Which means I executed libtool, autoconf, automake and cmake in Shell. I always choose a generic suggestion from Nix, without a specific version. Note: some commands may report errors as we executing them in a wrong way just to add to a replit.nix.
3.
Once build tools are set up we need to get and build TA-Lib C library sources. To do that execute in Shell:
git clone https://github.com/TA-Lib/ta-lib.git
then
cd ta-lib/
libtoolize
autoreconf --install
./configure
If configure script is completed without any problems, build the library with:
make -j4
It will end up with some compilation errors, but they are related to some additional tools which are used to add new TA-Lib indicators and build at the end, but not the library itself. The library will be successfully compiled and you should be able to see it with:
$ ls ./src/.libs/
libta_lib.a libta_lib.lai libta_lib.so.0
libta_lib.la libta_lib.so libta_lib.so.0.0.0
Now we have our C library built, but we can't install it to a system default folders. So we have to use the library as is from the folders where it was build. All we need is just one more additional preparation:
mkdir ./include/ta-lib
cp ./include/*.h ./include/ta-lib/
This will copy a library headers to a subfolder, as they are designed to be used from a such subfolder (which they don't have due to impossibility to perform the installation step).
4.
Now we have TA-Lib C library built and prepared to be used locally from its build folders. All we need after that - is to compile the Python wrapper for it. But Python wrapper will look for a library only in system default folders, so we need to instruct it where our library is.
To do this, execute pwd and remember the absolute path to your project's root folder. In my case it was:
/home/runner/FormalPleasedOffice
Then adjust the paths (there are two) in a following command to lead to your project path:
TA_INCLUDE_PATH=/home/runner/FormalPleasedOffice/ta-lib/include/ TA_LIBRARY_PATH=/home/runner/FormalPleasedOffice/ta-lib/src/.libs/ pip install ta-lib
This is one line command, not a two commands.If the paths would be shorter it would look like:
TA_INCLUDE_PATH=/path1/ TA_LIBRARY_PATH=/path2/ pip install ta-lib.
After execution of this command the wrapper will be installed with two additional paths where it will look for a library and its header files.
That's actually all.
An alternative way would be to clone the wrapper sources, edit its setup.py and install wrapper manually. Just for the record this would be:
cd ~/Your_project
git clone https://github.com/mrjbq7/ta-lib.git ta-lib-wrapper
cd ta-lib-wrapper
Here edit the setup.py. Find the lines include_dirs = [ and library_dirs = [ and append your paths to these lists. Then you just need to:
python setup.py build
pip install .
Note the dot at the end.
5.
Go to the project's folder and try our python script:
$python main.py
b'0.6.0-dev (Jan 1 1980 00:00:00)'
Bingo!
The #truf answer is correct.
after you add the
pkgs.libtool
pkgs.automake
pkgs.autoconf
pkgs.cmake
in the replit.nix dippendancies.
git clone https://github.com/TA-Lib/ta-lib.git
cd ta-lib/
libtoolize
autoreconf --install
./configure
make -j4
mkdir ./include/ta-lib
cp ./include/*.h ./include/ta-lib/
TA_INCLUDE_PATH=/home/runner/FormalPleasedOffice/ta-lib/include/ TA_LIBRARY_PATH=/home/runner/FormalPleasedOffice/ta-lib/src/.libs/ pip install ta-lib
Note : FormalPleasedOffice should be your project name
Done.
Here is the youtube video :
https://www.youtube.com/watch?v=u20y-nUMo5I

./python: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory

I need to try python 3.7 with openssl-1.1.1 in Ubuntu 16.04. Both python and openssl versions are pre-release. Following instructions on how to statistically link openssl to python in a previous post, I downloaded the source for opnssl-1.1.1.
Then navigate to the source code for openssl and execute:
./config
sudo make
sudo make install
Then, edit Modules/Setup.dist to uncomment the following lines:
SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
Then download python 3.7 source code. Then, navigate inside the source code and execute:
./configure
make
make install
After I execute make install I got this error at the end of the terminal output:
./python: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory
generate-posix-vars failed
Makefile:596: recipe for target 'pybuilddir.txt' failed
make: *** [pybuilddir.txt] Error 1
I could not figure out what is the problem and what I need to do.
This has (should have) nothing to do with Python or OpenSSL versions.
Python build process, includes some steps when the newly built interpreter is launched, and attempts to load some of the newly built modules - including extension modules (which are written in C and are actually shared objects (.sos)).
When an .so is loaded, the loader must find (recursively) all the .so files that the .so needs (depends on), otherwise it won't be able to load it.
Python has some modules (e.g. _ssl*.so, _hashlib*.so) that depend on OpenSSL libs. Since you built yours against OpenSSL1.1.1 (the lib names differ from what comes by default on the system: typically 1.0.*), the loader won't be able to use the default ones.
What you need to do, is instruct the loader (check [Man7]: LD.SO(8) for more details) where to look for "your" OpenSSL libs (which are located under /usr/local/ssl/lib). One way of doing that is adding their path in ${LD_LIBRARY_PATH} env var (before building Python):
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/ssl/lib
./configure
make
make install
You might also want to take a look at [Python.Docs]: Configure Python - Libraries options (--with-openssl, --with-openssl-rpath).
Check [SO]: How to enable FIPS mode for libcrypto and libssl packaged with Python? (#CristiFati's answer) for details on a wider problem (remotely) related to yours.
What I have done to fix this :
./configure --with-ssl=./libssl --prefix=/subsystem
sed -i 's!^RUNSHARED=!RUNSHARED=LD_LIBRARY_PATH=/path/to/own/libssl/lib!' Makefile
make
make install
Setting LD_LIBRARY_PATH with export was not sufficient
With Python-3.6.5 and openssl-1.1.0h i get stuck in the same problem. I have uncomment _socket socketmodule.c.

Unable to build SWIG.exe using MinGw

I am trying to install 'pocketsphinx' module in python which requires swig.exe. After a lot of searching I followed the steps mentioned in the swig site(http://www.swig.org/Doc3.0/Windows.html#Windows_swig_exe) to build an exe. But I am stuck at the last 2 steps.
When './autogen.sh' is executed, I get the following error message although the file 'aclocal' is present in the '/mingw/bin' directory.
vinay#DESKTOP-7LB2J5M /usr/src/swig
$ ./autogen.sh
+ test -d Tools/config
+ aclocal -I Tools/config
./autogen.sh: /mingw/bin/aclocal: No such file or directory
I renamed c:\MinGW\msys\1.0\etc\fstab.sample to c:\MinGW\msys\1.0\etc\fstab and also installed automake, libtool, autoconf, aclocal, autoheader dependencies from MinGW installation manager. What am I missing?
I am not familiar with MinGw or unix commands.

Installing pygraphviz on Windows 7 x64 for Python 3.5 x32 failing with fatal error LNK1120: 1 unresolved externals [duplicate]

I am trying to install pygraphviz on Windows 10. There are many solutions to this problem online, but none have yet worked for me. The precise problem I'm having is with this via jupyter notebook-->
[1] import networkx as nx
import pylab as plt
from networkx.drawing.nx_agraph import graphviz_layout
[2]G = nx.DiGraph()
G.add_node(1,level=1)
G.add_node(2,level=2)
G.add_node(3,level=2)
G.add_node(4,level=3)
G.add_edge(1,2)
G.add_edge(1,3)
G.add_edge(2,4)
nx.draw(G, pos=graphviz_layout(G), node_size=1600, cmap=plt.cm.Blues,
node_color=range(len(G)),
prog='dot')
plt.show()
I get the following errors after [2]:
ModuleNotFoundError Traceback (most recent call last)
C:\Users\name\Anaconda3\lib\site-packages\networkx\drawing\nx_agraph.py
in
pygraphviz_layout(G, prog, root, args)
254 try:
--> 255 import pygraphviz
256 except ImportError:
ModuleNotFoundError: No module named 'pygraphviz'
and
ImportError Traceback (most recent call last)
<ipython-input-2-86a15892f0f0> in <module>()
9 G.add_edge(2,4)
10
---> 11 nx.draw(G, pos=graphviz_layout(G), node_size=1600, cmap=plt.cm.Blues,
12 node_color=range(len(G)),
13 prog='dot')
C:\Users\name\Anaconda3\lib\site-packages\networkx\drawing\nx_agraph.py in graphviz_layout(G, prog, root, args)
226
227 """
--> 228 return pygraphviz_layout(G,prog=prog,root=root,args=args)
229
230 def pygraphviz_layout(G,prog='neato',root=None, args=''):
C:\Users\name\Anaconda3\lib\site-packages\networkx\drawing\nx_agraph.py in pygraphviz_layout(G, prog, root, args)
256 except ImportError:
257 raise ImportError('requires pygraphviz ',
--> 258 'http://pygraphviz.github.io/')
259 if root is not None:
260 args+="-Groot=%s"%root
ImportError: ('requires pygraphviz ', 'http://pygraphviz.github.io/')
Here's what I've tried to resolve this
(1) Regular pip install: "pip install pygraphviz" This is the error I get at the end. EDIT I get the same error even if I run cmd as admin.
Command "C:\Users\name\Anaconda3\python.exe -u -c "import setuptools,
tokenize;__file__='C:\\Users\\name~1\\AppData\\Local\\Temp\\pip-build-
n81lykqs\\pygraphviz\\setup.py';f=getattr(tokenize, 'open', open)
(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code,
__file__, 'exec'))" install --record C:\Users\name~1\AppData\Local\Temp\pip-
b3jz1lk5-record\install-record.txt --single-version-externally-managed --
compile" failed with error code 1 in C:\Users\name~1\AppData\Local\Temp\pip-
build-n81lykqs\pygraphviz\
(2) Downloading and installing graphviz-2.38.msi, and then downloading both the 64-bit versions of the wheel. This is the result.
C:\Users\name\Anaconda3>pip install pygraphviz-1.3.1-cp34-none-
win_amd64.whl
pygraphviz-1.3.1-cp34-none-win_amd64.whl is not a supported wheel on this
platform.
C:\Users\name\Anaconda3>pip install pygraphviz-1.3.1-cp27-none-
win_amd64.whl
pygraphviz-1.3.1-cp27-none-win_amd64.whl is not a supported wheel on this
platform.
What I would like to try, but am not sure how to do properly:
Edit setup.py. I have read a lot about people finding solutions in changing the paths, but I'm not really sure how to do this. This method looks very complex.
Thank you for any help/insight!
Updated the repo: [GitHub]: CristiFati/Prebuilt-Binaries - (master) Prebuilt-Binaries/PyGraphviz/v1.5:
Using official Graphviz 2.42.2 sources
.whls (win_amd64, win32) for currently supported Python versions
Newer versions might be added (check one level up)
For Python 2.7, they are already built: [UCI.LFD]: Unofficial Windows Binaries for Python Extension Packages - PyGraphviz, an interface to the Graphviz graph layout and visualization package..
Notes:
In some (I guess, most of the) cases, a Graphviz installation will be required on the system where PyGraphviz runs on, because PyGraphviz uses some of Graphviz's tools (executables). They can be downloaded, or built (they don't have to match PyGraphviz architecture (032bit (PC032), 064bit (PC064)), as they are invoked). Update: I also added Graphviz 2.42.2 build (PC032 - as it works on both PC064 and PC032 Win) in the above repository
Check it for newer software versions
Also, a bug (present in previous versions) was fixed. Check [SO]: pygraphviz 1.5 default edge no arrow? (#CristiFati's answer) for more details
Anyone who wants to know more details about the build process, read on!
1. Intro
Almost 2 years later, and the problem (well, not exactly as in the question) still persists.
I want to start by emphasizing the difference between the 2 packages:
[PyPI]: pygraphviz - Download files: the one in question
[PyPI]: graphviz - Download files: (a simpler) one with a similar name
In Anaconda environment, [SO]: Installing PyGraphviz on Windows 10 64-bit, Python 3.6 (#TomHanks's answer) works perfectly.
PyGraphwiz only has available for download an archive (.zip, in this case) file, meaning that it contains (C / C++) sources.
A couple of words about packages (.whls) whose names contain things like cp34-none-win_amd64 (check [SO]: What does version name 'cp27' or 'cp35' mean in Python? (#WayneWerner's answer) for details):
They contain binaries (.so or .pyd (.dll)), which are linked against a specific Python library
They are meant to work only with that Python version (so 34 is not meant to work with Python 3.6)
Even is one somehow "outsmarts" PIP and manages to install such a package (it's not that hard, actually), it will fail at import time, or worse, it has a high probability of crashing Python
Now, many packages have prebuilt binaries for most common Python versions running on various OSes (e.g. [PyPI]: mysql-connector-python - Download files), but just as many don't, and those only contain sources. Unfortunately, PyGraphviz is in the 2nd category. For the latter ones, pip install will:
Download the sources
Build the sources locally
A C (C++) compiler is required, typically:
GCC on Nix
VStudio on Win
They might have other dependencies
Install the built artefacts (binaries and .py(c) files)
As a side note: pip -v ... enables verbose mode for the current command, which comes in extremely handy when experiencing install errors.
Back to our problem: Python 3.6 needs VStudio 2015 ([Python.Wiki]: WindowsCompilers).
This is a very vast topic, I covered some parts in:
[SO]: Simstring (python) installation in windows (#CristiFati's answer)
[SO]: How to build a DLL version of libjpeg 9b? (#CristiFati's answer)
You should check them before proceeding and also keep them open, as you will definitely need them in the next steps.
I have VStudio 2015 Community (among many other versions) installed, you should install it too, it's free ([MS.VStudio]: Still want an older version?).
PyGraphviz depends on [Graphviz]: Graph Visualization Software. So, at build time it will need (parts of) Graphviz (which also has other dependencies of its own) to be already built. Unfortunately, I couldn't find prebuilt binaries (there is [Graphviz]: Windows Packages - graphviz-2.38.zip, but that's not helping), so it will have to be built manually.
Before going further:
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow\q045093811]> "e:\Work\Dev\VEnvs\py_064_03.06.08_test0\Scripts\python.exe" -c "import pygraphviz"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'pygraphviz'
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow\q045093811]> dir /b
other
src
This is my top dir, any sources are downloaded in the src dir, binaries will be placed in the bin dir.
2. Build Graphviz
Before starting, I want to mention that I heavily rely on Cygwin (you don't have to, there are also other variants (MSYS2)), and some of my tools are installed there, so I'll be alternating between Cygwin and Cmd terminals (which might be confusing).
[Graphviz]: Graphviz Build Instructions for Windows states:
For building on Windows:
(Graphviz versions ≥ 2.41)
First, in the root of the repository, perform git submodule update --init. This will download all submodules, which are mostly the dependencies for the Windows build. Next, add the windows\dependencies\graphviz-build-utilities directory to your PATH (and restart Visual Studio or the prompt with which you execute msbuild after that). This folder contains the tools Bison, Flex and SED (and future additions) with versions that are tested. If all went right, the dependencies are now set up and you can build Graphviz.
First, we need to download everything:
[cfati#cfati-5510-0:/cygdrive/e/Work/Dev/StackOverflow/q045093811/src/graphviz]> ~/sopr.sh
### Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ###
[064bit prompt]> git clone https://gitlab.com/graphviz/graphviz.git .
Cloning into '.'...
remote: Enumerating objects: 71728, done.
remote: Counting objects: 100% (71728/71728), done.
remote: Compressing objects: 100% (19331/19331), done.
remote: Total 71728 (delta 52200), reused 71681 (delta 52157)
Receiving objects: 100% (71728/71728), 163.79 MiB | 480.00 KiB/s, done.
Resolving deltas: 100% (52200/52200), done.
Checking out files: 100% (3870/3870), done.
[064bit prompt]>
[064bit prompt]> git submodule update --init
Submodule 'dependencies/criterion' (https://github.com/Snaipe/Criterion.git) registered for path 'dependencies/criterion'
Submodule 'windows/dependencies/graphviz-build-utilities' (https://github.com/ErwinJanssen/graphviz-build-utilities.git) registered for path 'windows/dependencies/graphviz-build-utilities'
Submodule 'windows/dependencies/libraries' (https://github.com/ErwinJanssen/graphviz-windows-dependencies.git) registered for path 'windows/dependencies/libraries'
Cloning into '/cygdrive/e/Work/Dev/StackOverflow/q045093811/src/graphviz/dependencies/criterion'...
Cloning into '/cygdrive/e/Work/Dev/StackOverflow/q045093811/src/graphviz/windows/dependencies/graphviz-build-utilities'...
Cloning into '/cygdrive/e/Work/Dev/StackOverflow/q045093811/src/graphviz/windows/dependencies/libraries'...
Submodule path 'dependencies/criterion': checked out '301d143ea42c024f22b673b69c72a4cb3c8d151f'
Submodule path 'windows/dependencies/graphviz-build-utilities': checked out '050fff84ce195e0740878748760fd801eeb07b23'
Submodule path 'windows/dependencies/libraries': checked out '141d3a21be904fa8dc2ae3ed01d36684db07a35d'
[064bit prompt]>
[064bit prompt]> git show head
commit 89292b5945933b1501293c04894ed9cf886241be (HEAD -> master, origin/master, origin/HEAD)
Merge: 429d43615 97811bd35
Author: Stephen C North <scnorth#gmail.com>
Date: Mon Feb 4 08:09:40 2019 -0500
Merge branch 'wasbridge/graphviz-master' into HEAD
[064bit prompt]> git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
You'll end up with a dir that contains ~320 MiB of stuff. The dir contains a graphviz.sln file, which is a VStudio (2015) solution file which contains 63 projects.
Looking at the Anaconda or Python 2.7 PyGraphviz (built) package, it only depends on cgraph.dll, which in turn depends on cdt.dll, so only the 2 projects are relevant to us. Note that these 2 projects might not need all the Git submodules (so the dir might be trimmed down), but I didn't investigate further.
Unfortunately, the projects are only configured for 032bit (Win32 platform (pc032)). The 064bit one must be manually added (I did it from VStudio IDE - and also described the process in one of my answers that I referenced). After saving the projects, they will be shown as modified by Git:
[064bit prompt]> git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
(commit or discard the untracked or modified content in submodules)
modified: lib/cdt/cdt.vcxproj
modified: lib/cgraph/cgraph.vcxproj
modified: windows/dependencies/graphviz-build-utilities (modified content)
no changes added to commit (use "git add" and/or "git commit -a")
The 3rd item is because I needed to reset some security permissions on 2 executables (used when building cgraph):
bison.exe
flex.exe
which were not set properly (most likely, because of Cygwin).
You can build the 2 projects from IDE, but I chose command line ([MS.Docs]: MSBuild command-line reference) since I find it more flexible:
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow\q045093811]> sopr.bat
### Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ###
[prompt]> "c:\Install\x86\Microsoft\Visual Studio Community\2015\vc\vcvarsall.bat" x64
[prompt]> set PATH=%PATH%;%CD%\src\graphviz\windows\dependencies\graphviz-build-utilities
[prompt]> msbuild src\graphviz\lib\cdt\cdt.vcxproj /t:Rebuild /p:Platform=x64;Configuration=Release;SolutionDir=%CD%\src\graphviz\;OutDir=%CD%\bin\Win\dynamic\064\UCRTv140\md\Release\graphviz\ >build_cdt_064.txt 2>&1
[prompt]> echo %errorlevel%
0
[prompt]> dir /b
bin
build_cdt.txt
other
src
[prompt]> msbuild src\graphviz\lib\cgraph\cgraph.vcxproj /t:Rebuild /p:Platform=x64;Configuration=Release;SolutionDir=%CD%\src\graphviz\;OutDir=%CD%\bin\Win\dynamic\064\UCRTv140\md\Release\graphviz\ >build_cgraph_064.txt 2>&1
[prompt]> echo %errorlevel%
0
[prompt]> dir /b "bin\Win\dynamic\064\UCRTv140\md\Release\graphviz"
cdt.dll
cdt.dll.lastcodeanalysissucceeded
cdt.exp
cdt.lib
cgraph.dll
cgraph.dll.lastcodeanalysissucceeded
cgraph.exp
cgraph.lib
So, we have everything needed (2 .lib and 2 .dll files) in order to go on.
3. Build PyGraphviz
PyGraphviz sources are (downloaded from [GitHub]: pygraphviz/pygraphviz - (pygraphviz-1.5) pygraphviz-pygraphviz-1.5.zip and) unpacked in src/pygraphviz/pygraphviz-pygraphviz-1.5.
One more adjustment is needed to Graphviz (probably it's done as part of another project - an install step): preparing the header files:
[prompt]> mkdir include\graphviz
[prompt]> copy src\graphviz\lib\cdt\cdt.h include\graphviz
1 file(s) copied.
[prompt]> copy src\graphviz\lib\cgraph\cgraph.h include\graphviz
1 file(s) copied.
Unfortunately, PyGraphviz does not build OOTB, because of [GitHub]: pygraphviz/pygraphviz - Python 3 support. To fix that, [GitHub]: eendebakpt/pygraphviz - Workaround for PyIOBase_Type for Python2 on win must be applied. I adapted it to work with the current sources (as it doesn't work OOTB, as well :X( ) for graphviz_wrap.cpp only:
pygraphviz-1.5-all-pyiobase_b85d12ac22d39063f7dbcc396e825c563431e352.patch:
--- pygraphviz/graphviz_wrap.c.orig 2018-09-10 16:07:12.000000000 +0300
+++ pygraphviz/graphviz_wrap.c 2019-02-26 18:05:20.281741400 +0200
## -2988,7 +2988,18 ##
#if PY_VERSION_HEX >= 0x03000000
-extern PyTypeObject PyIOBase_Type;
+static PyObject *PyIOBase_TypeObj;
+
+static int init_file_emulator(void)
+{
+ PyObject *io = PyImport_ImportModule("_io");
+ if (io == NULL)
+ return -1;
+ PyIOBase_TypeObj = PyObject_GetAttrString(io, "_IOBase");
+ if (PyIOBase_TypeObj == NULL)
+ return -1;
+ return 0;
+}
#endif
## -3449,7 +3460,7 ##
{
#if PY_VERSION_HEX >= 0x03000000 || defined(PYPY_VERSION)
#if !defined(PYPY_VERSION)
- if (!PyObject_IsInstance(obj0, (PyObject *)&PyIOBase_Type)) {
+ if (!PyObject_IsInstance(obj0, PyIOBase_TypeObj)) {
PyErr_SetString(PyExc_TypeError, "not a file handle");
return NULL;
}
## -3523,7 +3534,7 ##
{
#if PY_VERSION_HEX >= 0x03000000 || defined(PYPY_VERSION)
#if !defined(PYPY_VERSION)
- if (!PyObject_IsInstance(obj1, (PyObject *)&PyIOBase_Type)) {
+ if (!PyObject_IsInstance(obj1, PyIOBase_TypeObj)) {
PyErr_SetString(PyExc_TypeError, "not a file handle");
return NULL;
}
## -6051,6 +6062,12 ##
SWIG_InstallConstants(d,swig_const_table);
+#if PY_VERSION_HEX >= 0x03000000
+ if (init_file_emulator() < 0) {
+ return NULL;
+ }
+#endif
+
PyDict_SetItemString(md,(char*)"cvar", SWIG_globals());
SWIG_addvarlink(SWIG_globals(),(char*)"Agdirected",Swig_var_Agdirected_get, Swig_var_Agdirected_set);
SWIG_addvarlink(SWIG_globals(),(char*)"Agstrictdirected",Swig_var_Agstrictdirected_get, Swig_var_Agstrictdirected_set);
That is a diff (patch). See [SO]: Run/Debug a Django application's UnitTests from the mouse right click context menu in PyCharm Community Edition? (#CristiFati's answer) (Patching UTRunner section) for how to apply patches on Win (basically, every line that starts with one "+" sign goes in, and every line that starts with one "-" sign goes out).
[prompt]> :: Restore the original prompt as cwd is important
[prompt]> exit
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow\q045093811]> set _TOP_DIR=%CD%
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow\q045093811]> pushd src\pygraphviz\pygraphviz-pygraphviz-1.5
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow\q045093811\src\pygraphviz\pygraphviz-pygraphviz-1.5]> pushd pygraphviz && "c:\Install\x64\Cygwin\Cygwin\AllVers\bin\patch.exe" -p 1 -buNi ..\pygraphviz-1.5-all-pyiobase_b85d12ac22d39063f7dbcc396e825c563431e352.patch && popd
patching file graphviz_wrap.c
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow\q045093811\src\pygraphviz\pygraphviz-pygraphviz-1.5]> echo %errorlevel%
0
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow\q045093811\src\pygraphviz\pygraphviz-pygraphviz-1.5]> "e:\Work\Dev\VEnvs\py_064_03.06.08_test0\Scripts\python.exe" setup.py install --include-path=%_TOP_DIR%\include --library-path=%_TOP_DIR%\bin\Win\dynamic\064\UCRTv140\md\Release\graphviz >%_TOP_DIR%\install_pygraphviz_064.txt 2>&1
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow\q045093811\src\pygraphviz\pygraphviz-pygraphviz-1.5]> echo %errorlevel%
0
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow\q045093811\src\pygraphviz\pygraphviz-pygraphviz-1.5]> popd
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow\q045093811]> set PATH=%PATH%;%CD%\bin\Win\dynamic\064\UCRTv140\md\Release\graphviz
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow\q045093811]> "e:\Work\Dev\VEnvs\py_064_03.06.08_test0\Scripts\python.exe" -c "import pygraphviz;print(dir(pygraphviz), \"\n\", pygraphviz.graphviz._graphviz)"
['AGraph', 'Attribute', 'DotError', 'Edge', 'ItemAttribute', 'Node', '__all__', '__author__', '__builtins__', '__cached__', '__date__', '__doc__', '__file__', '__license__', '__loader__', '__name__', '__package__', '__path__', '__revision__', '__spec__', '__version__', 'absolute_import', 'agraph', 'division', 'graphviz', 'print_function', 'release', 'test', 'tests', 'version']
<module '_graphviz' (e:\Work\Dev\VEnvs\py_064_03.06.08_test0\lib\site-packages\pygraphviz\_graphviz.cp36-win_amd64.pyd)>
As seen, the module was successfully imported.
As a remark, the 2 .dll dependencies (from previous section) must be available when the module is imported, so their dir is added to %PATH%.
Of course this is only a (lame) workaround (gainarie), this shouldn't happen every time one has to work with the package.
I don't know (yet) how to instruct setup.py to also copy them in the package build / install dir, so as an alternative (also workaround) one has to manually copy them in PyGraphviz install dir (next to _graphviz.cp36-win_amd64.pyd, which is (in my case): "e:\Work\Dev\VEnvs\py_064_03.06.08_test0\lib\site-packages\pygraphviz").
4. Shortcut
Since the whole process is complex and requires lots of manual interventions and hacks, I've managed to build (with minor setup.py modifications) the (.whl) package.
I am not aware of a simple way to make it publicly available, so (although maybe it's not the best practice,) I uploaded it at [GitHub]: CristiFati/Prebuilt-Binaries - (master) Prebuilt-Binaries/PyGraphviz/v1.5/pygraphviz-1.5-cp36-cp36m-win_amd64.whl.
Notes:
The following is regarding PyGraphviz, but it can be generalized and applied to any (.whl) package
Also, the GitHub repository will be used as an example, but (again) it can apply to (.whls in) any repository, including [PyPI]: The Python Package Index (I'm not using the PyGraphviz one as it has no binaries, but for example [PyPI]: numpy 1.17.0 - Download files)
You can download it locally (e.g. in C:\Path\to\downloaded), then install it like (this is one way, check [SO]: How to install a package for a specific Python version on Windows 10? (#CristiFati's answer) for alternatives):
"C:\Path\to\Python-3.6-amd64\python.exe" -m pip install "C:\Path\to\downloaded\pygraphviz-1.5-cp36-cp36m-win_amd64.whl"
The above .whl is located next to several others. Those are for different Python versions (and that happens when the .whl contains .dlls (.pyds) or .sos (on Nix) that link to a specific Python library). To match your Python version search the .whl name for cp${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}. In the current situation, it's cp36 corresponding to Python 3.6, but the same principle applies for other Python versions (cp37, cp38, cp39, cp310, cp311, ...). Check [SO]: What does version name 'cp27' or 'cp35' mean in Python? for more details.
Same thing for the architecture (win_amd64 / win32 (x86_64 / i686 on Nix)).
Note: It works for Anaconda environments as well!
The most voted answers seemed to be installing graphviz, rather than pygraphviz.
If you are using a conda environment, you may try using this channel:
conda install graphviz pygraphviz -c alubbock
I tried it out with networkx 2.1, it worked fine.
Here's what worked for me:
Win 7 AMD64
Install MSFT C++ compiler.
Install Anaconda for Win AMD64, Python3.
Install graphviz for Win.
Add C:\Program Files (x86)\Graphviz2.38\bin to your PATH environment variable.
Download pygraphviz-1.3.1-cp34-none-win_amd64.whl.
Create a Conda environment with Python version 3.4: conda create --name digraphs python=3.4 anaconda.
Enter the environment: activate digraphs.
Install pygraphviz using pip: pip install pygraphviz-1.3.1-cp34-none-win_amd64.whl.
Run example: python ./gviz_simple.py.
Exit the environment: deactivate
I put some stuff up on github about it. It's messy, use at your own risk:
https://github.com/darkhipo/Easy-Digraph-Draw
Solved it on Windows 10 64-bits and Python 3.6.
Steps:
Download Graphviz for windows from the graphiviz site.
Add the Graphviz bin path C:\Program Files (x86)\Graphviz2.38\bin in your Windows path.
Close and reopen your terminals so the path changes is recognized.
Download the graphviz python 3.6 wheel.
Install the graphviz wheel.
pip install graphviz-0.8.3-py2.py3-none-any.whl
Done!

How to fix "python does not have .gnu.prelink_undo section"

I need to package a virtualenv as an rpm. I found a sample spec file for plone here
My project uses python 2.7 and for that I've built python from source. Therefore I changed some of the spec file to
/usr/local/bin/virtualenv-3.4 --no-site-packages --distribute %{_builddir}/usr/local/virtualenvs/%{shortname}
I'm getting the following error on rpmbuild -bb requirements.spec
+ /usr/sbin/prelink -u /var/lib/jenkins/rpmbuild/BUILDROOT/requirements-1.0-1.x86_64/usr/local/virtualenvs/requirements/bin/python
/usr/sbin/prelink: /var/lib/jenkins/rpmbuild/BUILDROOT/requirements-1.0-1.x86_64/usr/local/virtualenvs/requirements/bin/python does not have .gnu.prelink_undo section
I'm assuming I need to rebuild python and enable the prelinking during the ./configure. How can I do that?
I had a similar issue recently with a SPEC file that was also based on this example from plone.
In my case I'm using python27 RPMs from IUS repository and want to avoid building it from source.
My workaround was to disable prelink completely in my SPEC file:
add this: %define __prelink_undo_cmd %{nil}
comment out this:
# # This avoids prelink & RPM helpfully breaking the package signatures:
# /usr/sbin/prelink -u $RPM_BUILD_ROOT/usr/local/virtualenvs/%{shortname}/bin/python

Categories

Resources