Whilst trying to install Boost Python on Visual Studio I have been getting few results. I was able to create the Boost.Python library and the boost_python...lib file has also been created which took me long to figure out how to achieve this.
However, now in visual studio, after adding the include and library path to the linker, I was not able to get a small test program to work.
When trying to run the following line of code:
Py_Initialize();
using namespace boost::python;
object main_module((handle<>(borrowed(PyImport_AddModule("__main__")))));
I am getting the following error
The program could not start because boost_python-vc141-1_65.dll is missing....
When I look in the boost folder just where the libraries are (in the stage folder) I can clearly see this file and I have linked the program against this folder.
I have tried various different Boost versions.
The latest stable build so 1.64 has the same problem as the beta 1.65. With a previous build, 1.61, I couldn't even get the Boost.Python to build.
I also tried different Python versions, 3.6 and now 2.7. I have uninstalled all other versions of Python so that the 2.7 version is the only one. I also made sure that the PYTHONHOME and PYTHONPATH are set in the system variables.
?
Am i missing something important to get this Boost Python library to work? If any other information are needed please ask and I will add it, but since i'm unfamiliar with boost and linking in general i'm not sure what information is relevant.
On Windows there isn't /usr/shared directory, so boost build script can't install a dll library for everybody. So you're supposed to do the job yourself.
Your dll files must be in the same directory with your exe file. When you compiled boost, it created dll library in the boost output dir (search for this file). So, you have to copy this *.dll file to your output directory (where C++ compiler/linker create your *.exe) via custom build step or something.
If SafeDllSearchMode is enabled, the search order is as follows:
The directory from which the application loaded.
The system directory. Use the GetSystemDirectory function to get the path of this directory.
The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched.
The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
The current directory.
The directories that are listed in the PATH environment variable. Note that this does not include the per-application path
specified by the App Paths registry key. The App Paths key is not
used when computing the DLL search path.
If SafeDllSearchMode is disabled, the search order is as follows:
The directory from which the application loaded.
The current directory.
The system directory. Use the GetSystemDirectory function to get the path of this directory.
The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched.
The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
The directories that are listed in the PATH environment variable. Note that this does not include the per-application path specified by
the App Paths registry key. The App Paths key is not used when
computing the DLL search path.
Taken from here
Related
I'm having a hard time understanding and running a terminal. I downloaded python 3.11 from the official website and installed it. I also checked the box at the beginning of the installment to add python to PATH. But when I try to run it on git bash it just gives me an empty line. On Visual code, It takes to download python through the Microsoft store. But is it makes sense to download it twice, through the website and through the store...?
git bash picture:
visual code terminal picture:
On Visual code, It takes to download python through the Microsoft store
If my understanding is correct, Windows comes with dummy python executables python.exe and python3.exe that take you to the microsoft store to install it- after which it is a real python executable instead of a dummy one. If you run where python, you'll get a list of all the python executables that are found via the PATH variable in the order that they are found in the PATH, where one of them will be the Windows one (instead of the one you installed from the Python website). Likely, the one you'll see listed first will be C:\Users\you\AppDate\Local\Microsoft\WindowsApps\python.exe.
What you probably need to do is update the order of entries in your PATH environment variable so that the directory containing the one you installed from the Python website is earlier in the PATH environment variable than the directory of the out-of-box Windows one.
Note: As indicated in this question: why must python executable path be added to system PATH environment variables for python command to work in visual studio code, you might need to add the directory containing your from-website Python to the system PATH environment variable (before/above the path to the directory of the system one) (as opposed to the user PATH environment variable).
I need help to troubleshoot the installation of gspread for an GAE app.
On my Windows PC, I have python.exe in C:\python27.
I installed gspread by running its setup.py from its distribution folder as follows:
c:\python27\python.exe setup.py install --home=X
The following folder and files were created in X\lib\python:
request-2.9.1-py2.7.egg (a folder)
easy-install.pth
gspread-0.2.5-py2.7.egg
site.py
Why lib\python? Is this sub-folder hardcoded somewhere?
When I launch my Python interpreter, I can then import gspread. sys.path includes the fully qualified path to X\lib\python\gspread-0.2.5-py2.7.egg. Note it's a path to a file and not a folder.
How does Python know where to locate gspread? I tried looking in C:\python27 for clues but could not find anything related to gspread, not even in the site-packages folder.
Python searches sys.path in order. It is likely that Python is importing gspread using the contents of the egg. Note that if Python finds a match before the gspread egg, it will stop on the first matching entry in sys.path. For example if you have a module named gspread in the current working directory, then Python will not use the egg.
If you want to modify the package, you have many different options. I suggest to first uninstall the current egg. Then place the folder named gspread in site-packages.
An even better alternative is to add the gspread source directory to PYTHONPATH. You can change the PYTHONPATH environment variable by
My Computer -> Properties -> Advanced > Environment Variables
When you defined --home option setuptools is simulating linux Home directory thats why the installation location goes to X:\lib\python.
My guess is this home path is getting added to Python env on the system sorry I don't have windows to test this but there is some info here: https://docs.python.org/2.3/inst/alt-install-windows.html
I often create python projects that offer both a package and an executable where it makes sense to call them by the same name. For example, I created a password program utility abraxas that includes a program that generates passwords for me, and also provides a python library package that allows me to access passwords from other python scripts. Whenever I do this I struggle with organizing my files. I have the following constraints that I am trying to satisfy:
Once installed, both the executable and the library should have the same name to highlight the relationship between the two (meaning that I would like to run the program using 'abraxas' and import the package with 'import abraxas').
I must be able to run the program from the source directory without formally installing the executable (to speed up debugging).
I must be able to directly import the package into the executable.
I would like to avoid hacking sys.path.
I am using linux, so I don't want to add silly extensions to my executable, such as .exe.
Normally the executable and package would be in the same directory, but this does not work in this case because the names conflict.
Alternatively, I could place the executable in a different directory, but then the program would not run without first installing it because it cannot naturally find the package.
The only solution I have found to this problem is to change the name of the executable in my source directory and place it next to the package directory; then rename the executable after installing it.
Can anyone suggest a better solution to this problem?
First off, I do not know python. I think that's why I am having a problem.
I am trying to build compiz from source but am stuck at building the simple-ccsm.
The setup of simple-ccsm is using python and a setup.py.
While installing, it complains :
Package compiz was not found in the pkg-config search path.
Perhaps you should add the directory containing 'compiz.pc'
to the PKG_CONFIG_PATH environment variable
No package 'compiz' was found
Now, the PKG_CONFIG_PATH does point to the correct folder. What's more, pkg-config can also find compiz correctly:
pkg-config --libs compiz
It does install simple-ccsm but, when I run it, simple-ccsm fails complaining
ImportError: No module named compizconfig
I have installed all the required dependencies for simple-ccsm ( including compizconfig-python bindings which seems to give the above error generelly)
So, I would like to ask the python experts, how do I guide python to look in the correct place. I am guessing it's somehow not looking in the correct directory.
To guide Python to the right place, you may need to tinker with PYTHONPATH: (Editing because link is broken).
PYTHONPATH sets the search path for importing python modules:
PYTHONPATH Augment the default search path for module files. The format is
the same as the shell’s PATH: one or more directory pathnames separated by
os.pathsep (e.g. colons on Unix or semicolons on Windows). Non-existent
directories are silently ignored.
In addition to normal directories, individual PYTHONPATH entries may refer
to zipfiles containing pure Python modules (in either source or compiled
form). Extension modules cannot be imported from zipfiles.
The default search path is installation dependent, but generally begins with
prefix/lib/pythonversion (see PYTHONHOME above). It is always appended to
PYTHONPATH.
An additional directory will be inserted in the search path in front of
PYTHONPATH as described above under Interface options. The search path can
be manipulated from within a Python program as the variable sys.path.
To set the variable, either specify it when you run your python script:
PYTHONPATH=/blah/whatever/ python somescript.py somecommand
Or export it to your Bash environment:
export PYTHONPATH=/blah/whatever/
I use CMake to create build scripts (Makefiles + VS solutions) for my projects. As best practice I create the build scripts in a separate folder (out of source). I build the projects in the same folder.
This works fine for compiled programs but I can't find an adequate solution for my Python scripts as these have no build step that would copy (build) them to the build folder.
Looking for creative solutions....
Requirements:
All executables should be available in the build folder post build (I consider *.py files to be executable
Python scripts should be easily managed using an IDE (spyder, eclipse, etc)
Source folder with python scripts is in Git repository. Build folder is not.
C++ compiled python modules should reside next to relevant python scripts
So far I considered two options:
Copy scripts to build folder when running CMake - Need to run CMake for every change in python files (IDE unfriendly). Can cause confusion: which copy of the sources to edit?
Create links to source folder in build folder - Multi platform mess. Problem deploying compiled c++ python modules next to the scripts without polluting source folder.
I hope this is clear enough.
Eventually I found a solution which involves creating symbolic links to the python sources and other related files that are not compiled but are necessary in the build environment. To allow mixing built modules with the symbolic links I used real folders instead of symbolic links.
This way:
There is one copy of the python scripts
It can be run/edited seamlessly from the binary folder
Utility function:
function (create_symlinks)
# Do nothing if building in-source
if (${CMAKE_CURRENT_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
return()
endif()
foreach (path_file ${ARGN})
get_filename_component(folder ${path_file} PATH)
# Create REAL folder
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${folder}")
# Delete symlink if it exists
file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/${path_file}")
# Get OS dependent path to use in `execute_process`
file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${path_file}" link)
file(TO_NATIVE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${path_file}" target)
if (UNIX)
set(command ln -s ${target} ${link})
else()
set(command cmd.exe /c mklink ${link} ${target})
endif()
execute_process(COMMAND ${command}
RESULT_VARIABLE result
ERROR_VARIABLE output)
if (NOT ${result} EQUAL 0)
message(FATAL_ERROR "Could not create symbolic link for: ${target} --> ${output}")
endif()
endforeach(path_file)
endfunction(create_symlinks)
Usage for a python module (inside CMakeLists.txt):
# Do not omit !!!RELATIVE!!!
file(GLOB_RECURSE files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.py *.dat *.xml)
create_symlinks(${files})
Usage:
cd src_dir
mkdir build_dir
cd build_dir
cmake ..
IMPORTANT:
When adding new files don't forget to run cmake
On Windows mklink support only some Windows versions
On Windows mklink can be run as Administrator only. A workaround can be found here.
Use relative paths when calling create_symlinks as this is how the directory structure is reconstructed in the binary folder.
I would compile the python script into the build folder by creating a custom command as is shown in this post.