我在Windows 10(64位)中下载了Python 3.6.2(64位)。现在我想开发Django框架,所以我想使用DECLARE @FileNameWithPath VARCHAR(max)
DECLARE @FileText VARCHAR(max)
DECLARE @FileId INTEGER
DECLARE @DynamicSQLMask AS NVARCHAR(max);
DECLARE @DynamicSQL AS NVARCHAR(max);
DECLARE @dynamicparamdec AS NVARCHAR(max);
--This is a string we'll use for our SQL Command.
-- The ''##FileAndPath##'' is a target string we will replace as we loop
-- over the file.
SET @DynamicSQLMask = ' SELECT @output = BulkColumn
FROM OPENROWSET(BULK ''##FileAndPath##'', SINGLE_BLOB) AS x'
DECLARE #MyCursor CURSOR FAST_FORWARD
FOR
SELECT x.FileId
FROM Files x
OPEN #MyCursor
FETCH #MyCursor
INTO @FileId
WHILE @@fetch_status = 0
BEGIN
BEGIN TRY
-- This is setup to read a number of files. This is where you would
-- Set the filename with path each time in the loop. For Example
-- Select @FileNameWithPath = 'C:\temp\myfile.txt'
SELECT @FileNameWithPath = FT.[DataFilesPath] + '\' + Finfo.X12FileName
, @DoNotProcess = FInfo.X12Fields
FROM Files x
WHERE x.FileId = @FileId
-- Here we are building the SQL we're going to execute. Sticking with
-- The example, @FileNameAndPath would hold 'C:\Temp\myfile.txt'
-- So it would replace '##FileAndPath##' 'C:\Temp\Myfile.txt'.
-- At which point @DynamicSQL would hold
-- ' SELECT @output = BulkColumn
-- FROM OPENROWSET(BULK ''C:\Temp\Myfile.txt'', SINGLE_BLOB) AS x'
SELECT @DynamicSQL = replace(@DynamicSQLMask, '##FileAndPath##',
@FileNameWithPath)
-- This is where you're setting up a parameter for our dynamic SQL.
-- It is an output parameter so it would return the text it reads from
-- the file. Read up on sp_ExecuteSql and passing parameters
-- if this part is confusing.
SET @dynamicparamdec = '@output varchar(max) output'
EXECUTE sp_executesql @DynamicSQL
, @dynamicparamdec
, @FileText OUTPUT
-- Here we store the contents of the file we read into a table.
UPDATE Files
SET [FileText] = @FileText
WHERE FileId = @FileId
END TRY
BEGIN CATCH
select 'load failed code here'
END CATCH
FETCH #MyCursor
INTO @FileId
END -- End the Cursor Loop.
--Close the cursor, if it is empty then deallocate it:
IF (
SELECT CURSOR_STATUS('global', '#MyCursor')
) >= - 1
BEGIN
IF (
SELECT CURSOR_STATUS('global', '#MyCursor')
) > - 1
BEGIN
CLOSE #MyCursor
END
DEALLOCATE #MyCursor
END
命令下载Django,但它显示错误。
pip
例外:
C:\Windows\system32>pip install django
Collecting django
Using cached Django-1.11.4-py2.py3-none-any.whl
Collecting pytz (from django)
Using cached pytz-2017.2-py2.py3-none-any.whl
Installing collected packages: pytz, django
答案 0 :(得分:2)
问题与您选择安装python的位置有关,通常它安装在C:\ pythonXX中,但您的安装位于C:\ Program Files \ pythonXX中。这总是会导致问题,您需要始终以管理员身份运行它。快速和最佳解决方案,卸载并接受在默认位置安装python - C:\ pythonXX
答案 1 :(得分:1)
使用Django的最佳方式是在虚拟环境中。在系统的Python 3.6中安装软件包将影响您在Python 3.6上运行的所有程序;如果你有多个Django应用程序,你的要求可能会混淆。
Django非常适合虚拟环境:有一个很好的教程here。实际上,您希望为每个项目设置一个虚拟环境,然后在该环境中干净地安装Django(及其依赖项)。这应该避免任何"访问被拒绝"或您遇到的其他错误。
仅作为虚拟环境如何帮助的示例:如果您需要为不同的应用程序使用不同版本的Django,它们应仅限于同一虚拟环境中的应用程序。然后,您可以在另一个应用程序的不同环境中以不同方式安装该程序包。这样,当你"导入django"从您的某个应用中,您知道自己获得了所需的版本。