반응형

pip 설치 UnicodeDecodeError: 'utf-8' 오류


파이썬의 pip를 사용해서 패키지(package)를 설치하던 중 다음과 같은 오류가 발생했다.

Exception:
Traceback (most recent call last):
  File "C:\Python36\lib\site-packages\pip\compat\__init__.py", line 73, in console_to_str
    return s.decode(sys.__stdout__.encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbf in position 48: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python36\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "C:\Python36\lib\site-packages\pip\commands\install.py", line 342, in run
    prefix=options.prefix_path,
  File "C:\Python36\lib\site-packages\pip\req\req_set.py", line 784, in install
    **kwargs
  File "C:\Python36\lib\site-packages\pip\req\req_install.py", line 878, in install
    spinner=spinner,
  File "C:\Python36\lib\site-packages\pip\utils\__init__.py", line 676, in call_subprocess
    line = console_to_str(proc.stdout.readline())
  File "C:\Python36\lib\site-packages\pip\compat\__init__.py", line 75, in console_to_str
    return s.decode('utf_8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbf in position 48: invalid start byte
728x90

관련 자료를 찾아보니 python36-32\lib\site-packages\pip\compat\__init__.py 파일을 수정하면 된다고 했지만, 이 방법으로는 해결되지 않았다.

 

해결 방법


필자의 경우 pip 패키지를 최신 버전으로 업그레이드하여 해결할 수 있었다.

기존에 설치된 pip 버전은 9.0.1로, 현재 포스팅 작성 시점의 최신 버전21.0.1로 업그레이드했다.

pip 업그레이드 명령어

인터넷에 연결된 PC에서 다음 명령어를 입력하면 pip가 업그레이드된다.

python -m pip install --upgrade pip

 

pip 업그레이드 명령어 (오프라인)

인터넷이 안 되는 PC에서는 아래 사이트에서 최신 pip를 다운로드 하고, 다음 명령어를 실행한다.

python -m pip install .\pip-21.0.1-py3-none-any.whl --no-index
반응형
반응형

C/C++ 포맷스트링


디버깅 환경이 별도로 구현되지 않은 프로젝트에서는 윈도우 기본 디버그 API인 OutputDebugString()을 사용해서 디버그 로그를 출력한다.

그러나 OutputDebugString()은 가변 인자 포맷 스트링(Formatted String)을 지원하지 않아서 상당히 불편하다.

 

MFC 환경에서라면 CString의 Format()으로 문자열을 어느 정도 구현할 수 있겠지만,

다른 C/C++ 프로젝트 환경에서는 std::stringstd::wstring을 주로 사용하기 때문에 포맷스트링을 매번 구현하기가 번거로운 편이다.

 

그래서 자주 사용되는 std::string의 포맷스트링 구현을 간단히 작성해두고 그대로 복사하여 사용한다.

 

아래에 멀티바이트(std::string) 및 유니코드(std::wstring) 환경에서 사용할 수 있는 두 가지 구현 코드사용 예제를 작성해두었다.

각 사용 환경에 따라 적절히 수정해서 활용하자.

728x90

 

std::string 포맷스트링 구현


멀티바이트 문자 집합(MBCS)용 구현 (std::string)

std::string format_arg_list(const char *fmt, va_list args)
{
    std::string s;

    if (fmt != nullptr)
    {
        int result = -1, length = 512;
        char *buffer = nullptr;
        
        while (result == -1)
        {
            if (buffer)
            {
                delete[] buffer;
            }
            buffer = new char[length + 1];
            memset(buffer, 0, (length + 1) * sizeof(char));

            result = _vsnprintf_s(buffer, length, _TRUNCATE, fmt, args);
            length *= 2;
        }
        
        s = buffer;
        delete[] buffer;
    }

    return s;
}
void DebugMessage(const char *fmt, ...)
{
    std::string msg;

    va_list ap;
    va_start(ap, fmt);
    msg = format_arg_list(fmt, ap);
    va_end(ap);

    msg += "\n";

    OutputDebugString(msg.c_str());
}

 

유니코드 문자 집합용 구현 (std::wstring)

std::wstring format_arg_list(const wchar_t *fmt, va_list args)
{
    std::wstring s;

    if (fmt != nullptr)
    {
        int result = -1, length = 512;
        wchar_t *buffer = nullptr;
        
        while (result == -1)
        {
            if (buffer)
            {
                delete[] buffer;
            }
            buffer = new wchar_t[length + 1];
            memset(buffer, 0, (length + 1) * sizeof(wchar_t));

            result = _vsnwprintf_s(buffer, length, _TRUNCATE, fmt, args);
            length *= 2;
        }
        
        s = buffer;
        delete[] buffer;
    }

    return s;
}
void DebugMessage(const wchar_t *fmt, ...)
{
    std::wstring msg;

    va_list ap;
    va_start(ap, fmt);
    msg = format_arg_list(fmt, ap);
    va_end(ap);

    msg += L"\n";

    OutputDebugString(msg.c_str());
}
반응형
반응형

원인


Visual Studio 2015 프로젝트 Git 관련 작업 중에 아래와 같이 VC.opendb를 액세스 할 수 없다는 오류가 발생했다.

 

Could not open 'C:/Solution1/Solution1.VC.VC.opendb': 다른 프로세스가 파일을 사용 중이기 때문에 프로세스가 액세스 할 수 없습니다.

VC.opendb는 Visual Studio 2015 부터 도입된 파일인데, Visual C++ IntelliSense의 데이터베이스이다.

기존의 .sdf 파일(SQL Server Compact Edition Database File)을 대체하는 역할을 담당한다.

 

VC.opendb 파일은 솔루션 및 프로젝트가 사용 중일 때만 생성되고 솔루션을 닫으면 자동 삭제된다.

 

그럼 솔루션을 오픈할 때 생성되는 VC.opendb를 왜 오픈하지 못하는 것일까?

 

728x90

 

해결


먼저 프로세스 모니터(Procmon)를 통해 해당 파일에 대한 핸들을 잡고 있는 프로세스를 살펴봤는데, Visual Studio의 devenv.exe 밖에 확인되지 않았다.

 

분명 Git 작업과 연관이 있을 것이라 생각하여 확인해봤는데, 솔루션 디렉터리에 .gitignore 파일이 존재하지 않는다는 사실을 발견했다.

.gitignore 파일은 깃에서 revision 관리를 원치 않는 특정 파일이나 확장자 또는 디렉터리 관리 대상에서 제외할 때 사용하는 파일이다.

 

이번 경우에는 해당 파일이 없었기 때문에 VC.db 와 같은 파일들이 버전 관리에 포함되어 git 프로세스와 충돌이 발생한 것이었다.

 

해결 방법은 간단하다.

.gitignore 파일을 솔루션의 루트 디렉터리에 생성하면 되는 것이다.

 

아래는 Visual Studio 2015의 기본 .gitignore 파일이다.

해당 내용을 복사해서 .gitignore 파일로 생성해도 되고, 아래에 첨부한 파일을 다운로드하여도 되겠다.

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
[Xx]64/
[Xx]86/
[Bb]uild/
bld/
[Bb]in/
[Oo]bj/

# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

# NUNIT
*.VisualState.xml
TestResult.xml

# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c

# DNX
project.lock.json
artifacts/

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# Chutzpah Test files
_Chutzpah*

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db

# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap

# TFS 2012 Local Workspace
$tf/

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

# JustCode is a .NET coding add-in
.JustCode

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*

# MightyMoose
*.mm.*
AutoTest.Net/

# Web workbench (sass)
.sass-cache/

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml

# TODO: Un-comment the next line if you do not want to checkin 
# your web deploy settings because they may include unencrypted
# passwords
#*.pubxml
*.publishproj

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets

# Microsoft Azure Build Output
csx/
*.build.csdef

# Microsoft Azure Emulator
ecf/
rcf/

# Microsoft Azure ApplicationInsights config file
ApplicationInsights.config

# Windows Store app package directory
AppPackages/
BundleArtifacts/

# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/

# Others
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
*.mdf
*.ldf

# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings

# Microsoft Fakes
FakesAssemblies/

# GhostDoc plugin setting file
*.GhostDoc.xml

# Node.js Tools for Visual Studio
.ntvs_analysis.dat

# Visual Studio 6 build log
*.plg

# Visual Studio 6 workspace options file
*.opt

# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions

# LightSwitch generated files
GeneratedArtifacts/
ModelManifest.xml

# Paket dependency manager
.paket/paket.exe

# FAKE - F# Make
.fake/

.gitignore
0.00MB

반응형

+ Recent posts