I have a file that I want to "cythonize", myfile.pyx. I also have a helper file, myhelper.pxi.
myfile.pyx contains within it the following line:
include 'myhelper.pxi'
If the helper file was not needed, I think setup.py would look like this:
from distutils.core import setup
from Cython.Build import cythonize
import numpy
setup(
ext_modules = cythonize("myfile.pyx")
)
Can you tell me how to properly incorporate the helper file into the setup.py code?
It's fine as is - setup.py only needs to know about "myfile.pyx". It doesn't need to know about the internal details of "myfile.pyx" (i.e. what files it textually includes).
This does mean that setup.py won't recompile things when you've only changed "myhelper.pxi" because it doesn't know about the dependency. There isn't really a good way round that. Use --force on the command line to make setup rebuild everything if that's a problem.
Related
import csv
fails, alert "csv.py" is not accessed
yes, there is no file of that name in my current working directory.
Where can I locate a copy of csv.py to use in my current project.
import urllib.request, urllib.error, urllib.parse #this command works
import obo #this command works because I have obo.py in my directory
import csv # csv is underlines with white dots, csv is not accessed
where do I seek csv.ph?
running windows Visual Studio version 1.73.1
Newbie error. The warning from Visual Studio only meant that I imported a module but didn't use it in the program.
I have made a game using pygame and now want to convert the script to an exe file. However, when doing this and starting the exe file I get an error saying "Failed to execute script (main.py)". I have tried everything from youtube videos to reading similar questions on Stack Overflow. But nothing works, I get the same error every time. How can I solve this?
Does it have to do something with my imports?
The import that I use in my script:
pygame
random
winsound
mixer (from pygame)
Avoid all of these problems and use PyInstaller (link to related question):
Download this library with pip by typing in the Command Prompt:
py -m pip install pyinstaller
Then, type cd [path to the file].
Finally, type py -m PyInstaller --onefile [script name].py.
PyInstaller will turn your code into one .exe file, in the folder dist, analyzing the modules you need.
After the installation, you can then delete all the other files, like the folder build for example.
If you need other attached files, like images, put them in the folder where the .exe file has been created.
Anyways, if you type exit() anywhere in your code, PyInstaller will raise an error. Simply import sys and type sys.exit() instead.
The repo works on my machine but not on gcloud.
Structure of repo (on Google Cloud Source Repo):
project/
├── localdep.py
└── mylocalpackage/
└── main.py
In main.py:
import localdep
Yet I receive the following error:
ModuleNotFoundError: No module named 'localdep'
What am I doing wrong?! There is no problem running this on Pycharm on my machine, yet when I push to gcloud there is...
The proper structure should be to have the main.py at the top level and the other files on the nested folders. You can take a look into this, which talks about Structuring Your Project.
Just in addition, I have tried with both from ..localdep import * and from ..package import localdep, and other like from ... import localdep, but either I receive ImportError: attempted relative import with no known parent package, or ValueError: attempted relative import beyond top-level package.
It worth to rethink your project structure.
Here is a simple Cython package:
foo/
__init__.py # Contains: from . import foo
foo.pyx
I use waf (I know pyximport or setup.py can be used too) to build the Python extension from foo.pyx:
foo/
__init__.py # Contains: from . import foo
foo.pyx
build/
foo/
foo.cpython-35m-x86_64-linux-gnu.so
I would like to import the foo package without installing it (development mode).
If the Python extension would be next to __init___ like this:
foo/
__init__.py # Contains: from . import foo
foo.cpython-35m-x86_64-linux-gnu.so
it would work, but __init__.py is in the the source directory while the .so file is in the build directory.
I would like to avoid copying .so files in source directory.
A solution solution would be to copy (with waf) foo/__init__.py in build/foo/__init__.py, and import the foo package in build/.
Is there other alternatives?
Source code is here.
https://scipher.wordpress.com/2010/05/10/setting-your-pythonpath-environment-variable-linuxunixosx/#comment-219
I did this tutorial to set up my pythonpath variable in my Linux computer,
the odd thing is that I can only import my modules from /home
I did cd /home and vi .bash_profile, did the changes pointing directly to my folder with my modules, such
PATH=$PATH:$HOME/bin:"/share/my_modules"
PYTHONPATH="$PYTHONPATH:/share/my_modules"
export PATH
export PYTHONPATH
and save the file.
from there I can do python and import my modules,
but if I go to any other directory and I try to import my modules, it fail =(.
if I do
import sys
sys.path
my folder /share/my_modules is not there =( but do show in the terminal from /home.
do I need to set up a .bash_profile file in each folder? I am missing something?
thanks guys.
https://help.ubuntu.com/community/EnvironmentVariables
reading this document, explains that are 2 ways to set it up,
one is modifying the /etc/environment file.
or making an sh file under /etc/profile.d/*.sh
and putting the variables like
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0
export PATH=$PATH:$JAVA_HOME/bin
that way every time a terminal is open will run that, export those variables and will work.