Cython cython.parallel unrecognized import - parallel-processing

I am trying to use parallelism in cython. I am not able to import the cython module 'parallel'.
I have tried the following variations to no avail:
from cython import parallel
import cython.parallel
cimport cython.parallel
from cython.parallel cimport prange
from cython.parallel import prange
At the top of a .pyx file. Nothing else is included in the file so far. I get red underlines for the first line's "parallel" and the last and second last line's "prange" with unresolved references. I am using cython version 0.27.
When typing the import statement
import cython.pa___________
once i type ".pa" the suggestions are "cython.set_initial_path, cython.test_assert_path_exists, cython.test_fail_if_path_exists, cython.wraparound". I am using Intellij PyCharm professional edition.
Other parallel code has the following usually at the top of their code:
from cython.parallel import prange
which does not seem to work or exist for me. Does anyone know what I am missing?

The correct incantation is from cython.parallel import prange. Note that you are editing a cython file, not a python file. PyCharm is pointing out issues that would be a problem if this were a python file.

Related

Get and install requirements.txt for python file into virtualenv

I have the following packages I need to install into my virtual environment for an app deployment. This is how they read at the top of my app's file:
import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_bootstrap_components as dbc
from dash.dependencies import Input, Output
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime, timedelta, date
from dateutil.relativedelta import relativedelta
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from scipy import stats
from sklearn import metrics
import plotly.express as px
import plotly.graph_objects as go
import plotly.figure_factory as ff
import statsmodels.api as sm
I'm not sure how to install the ones that say "from x import y, z". I'd also much prefer to do something more global(?) than install each thing one by one into the virtualenv.
As I understand it, the pip freeze > requirements.txt command only generates a requirements file based on what's manually been installed into the virtualenv. I'd rather get something together that looks at my app file and generates a requirements.txt based on that, and then install the contents of the requirements.txt into the virtualenv directly, as opposed to installing each package one by one.
from foo import bar is essentially equivalent to:
import foo
bar = foo.bar
It just imports the module then loads some of its variables into scope. So, from scipy import stats would be in the scipy module. As for automatically generating a requirements.txt, this is what pipreqs is made for.
I installed pipreqs and then used
pipreqs .
from command line while in the directory of the folder with the app in it. This generated a requirements.txt with all the proper packages. Still working on installing the requirements.txt into the virtualenv, but thats been answered many times elsewhere.
EDIT: install requirements.txt into virtualenv using:
pip install -r requirements.txt

Tensorflow .so issues Mac OS X

I am having trouble getting the Tensorflow example to progress beyond the first line of code beyond my imports. With no other errors, I receive the following:
NotFoundError: dlopen(/Users/opusandcaymus/Election/word2vec_ops.so, 6): image not found
I have a dedicated Tensorflow environment in Anaconda 4.0.1 running Python 3.5. Tensorflow was freshly installed in that environment as version 1.4.1. I'm not sure what the .os file does for word2vec, but Google's example problem requires this line (Google Example Link). Thanks in advance.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import sys
import threading
import time
from six.moves import xrange # pylint: disable=redefined-builtin
import numpy as np
import tensorflow as tf
word2vec = tf.load_op_library(os.path.join(os.path.dirname(os.path.realpath("__file__")), 'word2vec_ops.so'))

Py2exe enchant error

Hi i compiled my python script that includes enchant and when i try to execute my program i get the following error
ImportError: The 'enchant' C library was not found. Please install it via your OS package manager, or use a pre-built binary wheel from PyPI.
I run 64bit Windows.
My setup.py file looks like this
from distutils.core import setup
from glob import glob
from PyQt4 import QtCore, QtGui
import numpy as np
import sys
import os, os.path
import time
import exifread
import logging
import re
import datetime
import hashlib
import sqlite3
import MySQLdb as msql
import jsbeautifier
import enchant
import sys
import py2exe
import six
Mydata_files = []
for files in os.listdir('C:\\Users\\agis\\Dropbox\\PyWall\\Files'):
f1 = 'C:\\Users\\agis\\Dropbox\\PyWall\\Files\\' + files
if os.path.isfile(f1): # skip directories
f2 = 'Files', [f1]
Mydata_files.append(f2)
sys.path.append('C:\\Windows\\WinSxS\\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.1_none_e163563597edeada')
sys.path.append("C:\\Python27\\Lib\\site-packages")
setup(windows=['pywall.py'],
data_files = Mydata_files)
If i remove enchant from my script the executable run perfect.How i can include enchant to my exe.
Please see the documentation http://pythonhosted.org/pyenchant/tutorial.html#packaging-pyenchant-with-py2exe
"PyEnchant depends on a large number of auxilliary files such as plugin libraries, dictionary files, etc. While py2exe does an excellent job of detecting static file dependencies, it cannot detect these files which are located at runtime.
To successfully package an application that uses PyEnchant, these auxilliary files must be explicitly included in the “data_files” argument to the setup function. The function enchant.utils.win32_data_files returns a list of files which can be used for this purpose."
For this issue:----> Py2exe enchant error.
You can use the alternative solution, by downloading "language_check 2.x" which can be used to check the grammatical mistakes of your English. Also, can be used in Py2 & Py3.
https://pypi.org/project/language-check/

py2app throws [errno 35] Resource Not Available during unconditional imports

I'm using python 2.7 installed via macports, pyobjc, cocoa and notably scipy (via FlowCytometryTools) with py2app to create a small mac application. Py2app's setup.py run with sudo python setup.py py2app completes nicely with -A for testing, but is unable to complete when running without that parameter to create a full .app build.
The build process will get a variable distance through the unconditional imports and then give error: [Errno 35] Resource temporarily unavailable and immediately exit. The number of unconditional import lines that complete before the error occurs changes. The longest run so far was seen when running immediately after a reboot. I've tried running with and without removing the previous build/dist folders to no effect.
Modules not found (unconditional imports):
...
* builtins.int (Cython.Build.Inline, Cython.Compiler.ExprNodes, IPython.utils._tokenizeerror: [Errno 35] Resource temporarily unavailable
My setup.py looks like this:
import sys
sys.setrecursionlimit(1500) #required to avoid recursion triggered early exit in py2app while compiling scipy. (default is 1000)
from setuptools import setup
APP = ['FlowMac.py']
DATA_FILES = ['FlowMac_Main.xib']
OPTIONS = {'argv_emulation': True}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
and the imports section of my python file FlowMac.py looks like this:
from Cocoa import *
from Foundation import *
from AppKit import *
from FlowCytometryTools import * #file/data handling via scipy and pandas
from pylab import * #graphing histograms
Commenting out both the FlowCytometryTools and the pylab imports allows the py2app build to complete but of course renders the program nonfunctional.
What is happening?
How can I get more information on which resource is unavailable?
was hitting a recursion limit a clue to my problem?
I'm running Yosemite on a MacBook Pro with 8GB RAM, so I'm very surprised to be hitting a wall here.
Thanks for your time.
UPDATE 4/29/2015:
Importing everything works fine if I remove my .xib from the datafiles array of the py2app launcher setup.py. A blank file with just import Cocoa, Foundation and Appkit works fine. Importing the xib with any one of FlowCytometryTools, pylab, scipy, matplotlib, numpy does not work. pylab and FlowCytometryTools rely on the other three, and any one of scipy, matplotlib or numpy brings in py2app recipies for the other two. One of these recipies isn't working with the xib, but I don't know why...
No experience with py2app, but I am wondering if you tried generating a more minimal version of the code that would fail to aid troubleshooting?
Maybe having FlowMac.py include nothing but the import statements:
import Cocoa
import Foundation
import AppKit
import FlowCytometryTools
import pylab
Also could you narrow it down to whether the problem appears due to pylab or due to FlowCytometryTools? (By commenting them out individually?)
From my testing, this error seems to be caused by the log output itself from py2app. Try redirecting standard error to a file:
python setup.py py2app 2>error_log
This should work around the error.

IPython fails to load win32api

I'm running Python 2.7 on windows and I've installed the pywin extension here.
Having done so, if I launch a normal python shell, I can import win32api perfectly.
If I do the same on IPython, I get this :
In [1]: import win32api
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
C:\Windows\system32\<ipython console> in <module>()
ImportError: DLL load failed: The specified module could not be found.
In [2]:
Why would it work in a normal python shell, but not IPython?
I had the same issue, and found a solution for my problem here. Apparently it's a conflict between pythoncom24.dll and pywintypes24.dll.
Look in your root Python install folder. If you find these two DLLs there, move them to \Python24\Lib\site-packages\win32 instead. This should fix your import conflict.
Alternately, you can control the imports explicitly. Add the following to your script in this order:
import pywintypes
import pythoncom
import win32api

Resources